Jump to content

Photo

Script to move something along its local axis

script scripting

  • Please log in to reply
4 replies to this topic

#1
YouDoNotKnowMyName

YouDoNotKnowMyName

    Overseer of Vault 114 / Destroyer of Precombines

  • Members
  • PipPipPipPip
  • 1,896 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"?



#2
Minuos

Minuos

    Regular

  • Members
  • PipPip
  • 60 posts

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.



#3
YouDoNotKnowMyName

YouDoNotKnowMyName

    Overseer of Vault 114 / Destroyer of Precombines

  • Members
  • PipPipPipPip
  • 1,896 posts

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.



#4
Minuos

Minuos

    Regular

  • Members
  • PipPip
  • 60 posts
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, 30 November 2021 - 10:23 PM.


#5
YouDoNotKnowMyName

YouDoNotKnowMyName

    Overseer of Vault 114 / Destroyer of Precombines

  • Members
  • PipPipPipPip
  • 1,896 posts

I will probably make a three functions, "MoveAlongLocalX", "MoveAlongLocalY", and "MoveAlongLocalZ".

 

I can figure this out, but I just thought that maybe there was an "easy" way to do this ...

 

Time for some trigonometry!







Also tagged with one or more of these keywords: script, scripting

IPB skins by Skinbox
Page loaded in: 1.001 seconds