Jump to content

Need help to calculate Offsets... :[


Hoamaii

Recommended Posts

Ahem, I feel stupid but I've never been that good at Maths... :facepalm:

 

Basically, I need to position an object in the world relatively to the player on the X axis minus 40.0 units and on the Y axis minus 6 units but sins and cos are a complete puzzle to me...

 

I've been trying to work around my math-proof mind by reproducing my offsets on a .nif marker and spawning that marker before using "MoveTo(Marker, 0.0, 0.0, 0.0, true)" on my object BUT the game keeps spawning that marker randomly on the Z axis no matter how much I call "Marker.SetAngle(0.0, 0.0, Game.GetPlayer().GetAngleZ())"...

 

So I'm kind of ashamed to ask, but anybody can help me figure that one out?... Please?

 

Many thanks in advance!.. :smile:

 

 

Edit: after digging through Skyrim's CK wiki and unsuccessfully trying my own calculations, let me rephrase that: I need to position an object 40 units to the left hand-side of the player, and 6 units behind the player...

Link to comment
Share on other sites

@shavKacagarikia:

 

Yes, I have and the object keeps translating randomly around the player, sometimes in front of him, sometimes behind him or way off to one side - like the game cannot detect dynamically precisely which direction the Player is facing - I'm currently in the process of Debugging "Game.GetPlayer().GetAngleZ()" to try and figure out what exactly is going on.

I've also tried "ObjectRef.MoveTo(PlayerRef, - 40.0 * Math.Sin(PlayerRef.GetAngleZ()), - 6.0 * Math.Cos(PlayerRef.GetAngleZ()), 0.0, true)" which also spawns the object randomly around the player on the Z axis (I'm aware my Sin and Cos operations are very wrong, but nonetheless it should move my object to the same position relatively to the player, which never happens).

 

The only thing which seems to work with fairly good precision is spawning the object directly on the player (using PlaceAtMe) and then "ObjectRef.SetAngle(0.0, 0.0, Game.GetPlayer().GetAngleZ())". But as soon as I try to move that Object again, it starts rotating around the player again... :wallbash:

 

 

Edit: Alright I just debugged several times "GetAngleZ()" on both player and placed object - Whether I use "Game.GetPlayer().GetAngleZ()", or "(Game.GetPlayer() as ObjectReference).GetAngleZ()", it returns the same value. And the object I "MoveTo(PlayerRef, etc.)" also returns the same value!.. So the object randomly rotating around my player is not due to the Game not detecting properly the Z angle... Darn!

Link to comment
Share on other sites

Alright, after much testing and debugging, I got everything else to work properly but MoveTo(...).

 

Basically, I'm trying to position a targeted actor 39.3 units to the left-hand side of the player (that's -39.3 on the X axis) and 5.3 units behind the player (that - 5.3 on the X axis) - and a puzzling cos and sin operation for me!.. - to get the player and the actor to be in the correct positions relatively to one another to play simultaneously 2 different sets of animations. Animations work fine, are perfectly timed and synchronized. I'm just stuck with that positioning issue.

 

I tried to find a work-around to my being unable to calculate cos and sins properly by creating a .nif marker which mimics the offsets on both axis. But that doesn't work, when moving my NPC actor to the marker, it will always move to the NiNode, not to the BSTriShape (makes sense). I could verify that in game by disabling actor's collisions - so I believe the actor being randomly rotating around the Player (after using "MoveTo") was probably a collision issue. The Z axis issue can be remedied by adding "myActor.SetAngle(0.0, 0.0, PlayerRef.GetAngleZ())".

 

So, once again, I'm just stuck to my cos and sin puzzle... :pinch:

Link to comment
Share on other sites

I honestly haven't used Sin or Cos since New Vegas so I'm not gonna be much help there, but did you try adding a new NiNode to your marker at your coordinates and using PlaceAtNode() instead of coordinates in your script? Might work for your purposes as long as your marker is matching rotation with the player, that NiNode should always be in the same place relative to the player's Z rotation.

Edited by ZerasCETA
Link to comment
Share on other sites

@ ZerasCETA:

 

Thanks for trying to help :)

 

In fact, though I understand how PlateAtNode works, I don't know how to add a new NiNode to my Marker. Like I said, I tried to mimic my offsets on an Xmarker changing it's coordinates in Nifskope to match the X and Y that fit my purpose and using PlaceAtMe to spawn that Xmarker at the Player. But then, if I moveTo my 2nd actor to that Xmarker, it will spawn on the NiNode of that Xmarker .nif (which makes sense) and not on the BSTriShape.

 

I you wouldn't mind explainng to me how I could add a NiNode to a Marker to be able to use PlaceAtNode correctly, I'd very much appreciate it - I'm sure I'll find a use for that, or it may helps others. Many thanks in advance.

 

I the meantime, Reneer has been kind enough as to write that cos and sin formulat for me, here's how it goes in case it helps anyone else:

Object.SetPosition(
Object.GetPositionX() + XDistance * Math.cos(Object.GetAngleZ()) + YDistance * Math.sin(Object.GetAngleZ()),
Object.GetPositionY() - XDistance * Math.sin(Object.GetAngleZ()) + YDistance * Math.cos(Object.GetAngleZ()),
Object.GetPositionZ()

And it works perfectly fine - with a little adjustment of my initial XDistance and YDistance values, I managed to position both Player and NPC Actor precisely as I wanted them.

 

But if you don't mind explaining to me how to add a new NiNode to a marker, I'm very interested too! Thanks :).

Link to comment
Share on other sites

Ahhh, no problem, I couldn't figure this one out in past Gamebryo games myself but it suddenly clicked for me for this one. It's much more simple than you'd allow yourself to believe.

 

So in NifSkope, the primary NiNode cannot be manipulated, and anything you change in it's translation, rotation, or scale won't affect it. Changing the Translation, Rotation, or scale of a BSTriShape will affect the model, but not the nodes. To add a new node to attach to, just right click the primary NiNode (the one at the top of the hierarchy with everything else below it) and click Node >> Attach Node >> NiNode. This will put a new NiNode with no name at 0,0,0, rotation 0, 0, 0, Scale 1.0. Then to rename it, click the new NiNode, then in the lower panel right click the "Name" row and click "Edit String Index". There, type a new name, like "Object_Attach". The name really doesn't matter, as long as it's the same as what you use in your script. Adjust its translation, rotation and scale further down in the lower panel to match your purposes and that's it. In your script, make sure the node you're attaching to is the same name as the newly created one and you're golden. For this example, "ObjectToAttachTo.PlaceAtNode("Object_Attach", NewlyAttachedObject)"

Edited by ZerasCETA
Link to comment
Share on other sites

@ ZerasCETA:

 

Thank you a LOT for these detailed instructions - that'll be very helpful for some other plans I have for the same mod.

 

I have another question if you can spare the time :)

 

I figured the primary NiNode cannot be manipulated, however in my experience (Skyrim .nifs though), if you right click it and transform it, say rotate it and change the X,Y, Z coordinates, then click "Apply", the transformations you just made not only applied to all BSTriShapes blocks, but also to the Collision block - can't that still be done in F04?

 

The reason I'm asking is I need to change both size and XYZ coordinates on a static object to use it as a model for a furniture marker. The above described manipulations seem to work - at least the CK doesn't seem to mind much, but I can't visualy verify that because in Nifskope 2.0.0.preAlpha 6, the collision object's shape just doesn't show in the render window (it used to show properly in Nifskope 2.0.0. preAlpha 1 when I used it for similar purposes in Skyrim). So there's no way that I can make sure that the collision object has been resized and moved along with the BSTriShapes. Any idea how I could double check that?

 

Many thanks again :).

Link to comment
Share on other sites

if you apply a transform to the parent node to a collision mesh, it will apply that same transform to the collision mesh (just like it does with the BSTrisShapes).

 

If you want to scale a collision mesh, I think you can by applying a scale value (XSCL field) to a placed object reference, but that's the only way I know of that works. I haven't actually done much testing on that method, but there are a number of vanilla references that are scaled that way and don't seem to have bad collision.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...