- Home /
Multiple Coordinate Systems
Hello,
I am rotating a UI object about the localEulerAngles Z axis. After I rotate it, I want it to translate vertically along the rotated X axis. However, it seems that when I use the following code, the object still translates along the global coordinate system used in the canvas.
transform.localEulerAngles = new Vector3(0, 0, RollSlider.value);
transform.localPosition = new Vector3(0, PitchSlider.value,0);
How do I set up multiple coordinate systems such that when one object is rotated, any x, y, z translation happens in the new "rotated" coordinate system?
Answer by Glurth · Oct 25, 2018 at 04:57 PM
Transformation components apply Rotation, Scaling and Translation(move) but they are ALWAYS performed in the same order. If you need to apply one OUT of the standard order, the generally accepted method is to create a new empty game object in the transform tree, and put the object you want to transform, as "child" object of the empty one. This is how one puts the child object "in the coordinate system" of the parent object.
Now, you can apply some of the "transformation" to the main object, and some to it's parent object. In this particular situation, it sounds like you want to apply the move/translation to the main object, and it's rotation to the empty parent object (but I'm not sure, I could have that exactly backwards!).
Thanks! I think that will help. I am used to using Patran/Nastran, and in that tool you can create as many different coordinate systems as you would like. You just reference the coordinate system that object uses. I thought there would be something similar without having to mess with parents/children.
So I should clarify. I have two data items that are represented by sliders. One slider moves an object up/down in the global coordinate system and the other rotates it clockwise/anticlockwise in the UI Canvas. Both scripts work, but what I really want is for the image to move up/down in it's own local coordinate system based on the angle it is rotated. So if I rotate the image 45 degrees clockwise and then move vertical slider up, it should move to the top right corner. Right now it rotates 45 degrees clockwise and then moves to the middle of the top of the screen.
I think you're solution will work. But I have masks and when I try to create new parent objects it isn't working right, but I think that's because I'm not doing something right with layering the parents/children.