Jump to content

Script to move something along its local axis


Recommended Posts

Good morning everybody!

 

In the CK, you can toggle movement between the global XYZ axis and the local XYZ axis.

 

Is there any scripted way to move something along the local axis like that?

 

So something like self.TranslateTo(...) but not with absolute world coordinates but with relative movement and rotation from the current position and rotation of the object.

So like "move 10 units along the local X axis, 32 along the local Y axis, 0 along the local Z axis, rotate 90 degrees along the local X axis, ....".

 

 

Or do I have to do it the "hard way" and figure out the math behind doing this and calculate the new position and rotation in "absolute world coordinates"?

Link to comment
Share on other sites

IIRC you can calculate within a function. So:

self.TranslateTo(self.GetPositionX() + 10, self.GetPositionY() + 32, self.GetPositionZ(), self.GetAngleX() + 90, self.GetAngleY(), self.GetAngleZ(), 5, 10)

That should move the reference like you described without affecting the Z axis or YZ angles, at a movement speed of 5 and rotation speed of 10.

Link to comment
Share on other sites

What you described is moving on the global X Y Z axis.

 

What I mean is something like this:

Imagine you are standing somewhere and I tell you to move 3 steps forward.

You are not going to move 3 steps to the north (= global axis) you are going to move 3 steps forward from the point where you are standing (= coordinate system with the point of origin at your position, same rotation asx you).

That is what I want to do.

Link to comment
Share on other sites

Understood. To my knowledge, there's no natural way of doing this via script. If I'm right in thinking that, then the only way I can really conceive of it is by using the reference's Z angle as a basis for some number work for TranslateTo().


Starting point would probably be the fact that a reference's Z angle isn't limited to between 0 and 360, so you'd want to bring it into that range to calculate XY translation based on that. Conditionally adding or subtracting 360 until it's true should work.


You'd also need to approach X and Y differently based on whether or not the ref's Z angle was between 180 and 360(0) or 90 and 270, respectively, so the function knows whether to translate XY in positive or negative.


Getting the process down might be tricky. How's your maths?

Edited by Minuos
Link to comment
Share on other sites

  • Recently Browsing   0 members

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