I have been looking for a couple of days for an answer for this question, I still do not know if its me doing something wrong or if its how unity is mean to work, I couldn’t find any answer to this questions so forgive me if it should be obvious or I’m looking for the wrong words, I think that the answer will probably be very simple.
I’m very confuse about the use of transform.forward in my game, basically because it does not work how I believe it should, first in one scenario when I instantiate an object I cannot use transfom.forward because it us null (it will be equal vector3.zero basically), but them after use transform.Translate the transform.forward get the right value and I can use it as normally, which end up forcing me to write this little piece of code:
in this case when I first try to move this object forward is null so I need to get the “forward” position from somewhere else, after that, forward magically appear and I can use it normally, my questions is, why forward does not exist when I instantiate an object, why is it zero and why it magically appear when I use “translate”.
When something seems confusing like that, either use a step by step debugger or add logging (for exemple try Debug.Log(transform.name + " forward=" + transform.forward)) in relevant places for relevant data, should help you figure out what you’re doing wrong.
that is correct, forward “1” is set in z, not sure why I was expecting it to follow my sprite direction or something, should I be aiming to use “up” instead when working in 2d?
Red arrow = X axis = left/right
Green arrow = Y axis = up/down
Blue arrow = Z axis = forward/backward
*up/down/left/right/fwd/bwd is a recommendation and not mandatory, feel free to treat any axis as any direction.
Depends if you’re viewing in global or local.
Vector3.forward is a shorthand for say Vector3(0,0,1), it points to global z+ transform.forward gives the what is the blue arrow when you have an object selected and viewing in local mode( i think it’s just ‘x’ to switch) it’s like saying transform.TransformDirection(Vector3.forward). https://docs.unity3d.com/ScriptReference/Transform.TransformDirection.html
Oh right, I mostly work in 2d, I guess the vector2.forward is the x axis? Well that was good to know, thanks for clarifying, i don’t use them often, generally just create my own vector directions