- Home /
Defining the forward for an arbitrary mesh
Is there a way to define the forward vector for an arbitrary mesh?
Answer by Jessy · Jan 15, 2011 at 06:29 AM
A mesh has local space, and therefore three local axes. Your vertices exist in the local space, and can be transformed therein, however you like. Use Mesh.vertices and alter them as you see fit. The term "forward" is associated with positive Z, in Unity, but it's only a guide; nothing is required to "point" at the blue arrow in the editor.
It just become awkward to use functions such as LookAt if you go away from having Z forward, Y up.
ina, you loop through a copy of the vertices array, and apply a rotation (or other transformation matrix) to each. Then you assign the array back, like in the doc link I gave you.
Statement, I don't disagree at all. Z being forward is logical. A human sees in two dimensions, so the third one should be the one you can't see in. (You can block your Z-axis perception by putting your eyes against a wall, but they'll still see the wall.) That said, the convention should be ZYX ins$$anonymous$$d of XYZ, because we ran out of dimensions for Vector4s/Quaternions.
Answer by Peter G · Jan 15, 2011 at 12:38 PM
Mesh does not have a .forward
property, so I guess you want to edit the transform's forward Vector3.
In that case then there would be 2 ways depending on what you want to do:
transform.forward = someVector;
//This will point the objects z-axis in that direction.
The other way would be to do the old trick where you create an empty GameObject and parent your mesh to it. That would let you redefine the local z-axis to the empty GameObject.