- Home /
Self space coordinates change after quaternion rotation in an unexpected way
I had the following situation while writing a script for a local transformation:
I wanted to move an object along its local z axis, so I used: gameObject.transform.Translate(new Vector3(0,0,-1) * Time.deltaTime, Space.Self).
Now if i apply some rotation to the object and move it afterwards with the same Translation, its moving on different axes in Space.World (as expected) depending on its rotation. I wrote following code to track the position in self space:
InitialRotation = gameObject.transform.rotation;
currentPosInSelfSpace = InitialRotation* gameObject.transform.position;
Now I rotated the Object on 90, 180 and 270 degress around y-axis at the start and observed how local coordinates are changing while I move the object. I realized that the value changed while moving in (0,0,-1) direction at the horizontal Axis (x-axis in Space.World)
For example: 10* (0,0,-1) movement
(With no rotation) self space coords: (0,0,-10)
(With 90 degrees rotation)self space coords: (0,0, 10)
(With 180 degrees rotation) self space coords: (0,0,-10)
(With 270 degrees rotation)self space coords: (0,0, 10)
The idea behind this is that I want to have an automated estimation of points based on the local transformation of multiple objects. So that each point has the same distance from its specific Object in the direction defined by the input vector. My fix for that would be to check how the rotation of each object is and then multiply currentPosInSelfSpace with -1 or not. But I dont necessarily want that and maybe I'm getting something wrong. I want to understand the concept of rotations more deeply.
Your answer