- Home /
The question is answered, right answer was accepted
Inheriting Parent Rotation and position
I have a Cube (instantiated in C #) encapsulated in a Plan (instantiated with the editor). The plane is vertical to the world (I rotated it 90 degrees) The Gizmo of the plane has therefore rotated, and its Y axis is horizontal now. Likewise, the Gizmo Y of the cube is horizontal (in the editor), except that by modifying its Y in C #, it refers to the Y of the world (vertical), and not to that of its Gizmo (horizontal).
your thoughts about this?
Answer by IvovdMarel · Oct 23, 2018 at 04:14 PM
Depending on how you are modifying the y, you should look at
Global:
//These two lines do the exact same thing.
transform.postition += new Vector3(0,5,0);
transform.Translate(0,5,0, Space.World):
Local:
//These two lines do the exact same thing.
transform.localPosition += new Vector3(0,5,0);
transform.Translate(0,5,0, Space.Self):
Answer by SuperScience · Oct 23, 2018 at 04:18 PM
Hi,
There are 2 coordinate systems for any game object. There is the world coordinates, and the local coordinates.
The world coordinates are the position and rotation relative to the world.
The local coordinates are the position and rotation relative to the parent object.
If you made a cube a child of a plane, then rotated the plane 90 degrees on the X axis, the local "Up" direction of the cube is now sideways, but the global is still going to be "Up".
I'm not sure what your question is specifically, but I hope that this clarifies some things for you.
I assume that the actual problem that you are having is that you want the objects to behave in one coordinate system, but they are using the other.
In the editor, you can switch the Gizmos between local and global with this button:
In script, use
transform.localPosition // local position
transform.position // global position
(and the same thing for rotation).
Let me know if this helps