From this tutorial: How To Make a 2.5D Game With Unity Tutorial: Part 1 | Kodeco
I stopped right when he said kinda explained about translating the object’s position based on the rotated plane, I honestly didn’t understand the relation between the plane and the object, and why changing the Z axis in the script caused the object to change X axis instead (therefore moving “forward” in the orthographic view).
Can someone explain this to me? It would be much appreciated…
1 Answer
1
In working with Unity, you need to understand your frame of reference and the difference between local and world coordinates. Local coordinates are from the frame of reference of the object. Take any game object you create/import into unity with a rotation of (0,0,0). The side facing the positive Z axis will always be the local ‘Z’ for that object (also called the object’s forward) no matter which way the object is rotated. When you bring the plane model into Unity (with rotation (0,0,0)), the front of the plane is facing ‘Z’.
As a test, rotate the plane to a variety of angles and hit play The plane will always move towards it own ‘Z’ axis (i.e. forward).
Note you can change the behavior of Transform.Translate() by add the optional space parameter.
transform.translate(speed * Time.deltaTime,0,0, Space.World);
With this new parameter added, movement will be with respect to the world axes, not the local axes of the object. Change the code to use the above line. Rotate the plane to other arbitrary angle and hit play. It will go from left to right no matter what the rotation of the plane.
So "my" Z will always go forward? If my object face right (after rotating 90º), I'll increase my Z axis no matter what that axis means for the world to move forward? Unity Editor shows me "X" increasing in the object's inspector window, I take that is the world's corresponding axis to my relative Z axis, right? I'm slowly getting it, sorry for asking such a very trivial question, I tend to question everything. :/ @Edit Wow really, this just lighted up in my mind, I guess that gizmo and those arrows to move the object are the actual world axes.
– PauloCF