Issue with Vector3.forward
Hi all, I created a practice scene in Unity to test out some functions, I am a beginner. I noticed that using Vector3.forward in different contexts creates different results and I don't understand why.
I created a sphere in my scene and added a script to it. If I use the command:
force.AddForce (Vector3.forward * 10)
The sphere moves towards the global z-axis as it should but if I use the command:
transform.Translate(Vector3.forward);
The sphere moves towards the global negative z-axis because that's where the sphere's z-axis is pointing.
I don't get why in the first command, Unity uses the global axis and in the second command, it uses the local axis of the sphere even though the direction is the same(Vector3.forward).
Answer by MakeCodeNow · Sep 06, 2015 at 02:42 AM
Vector3.forward is just a convenient way of saying new Vector3(0,0,1). It doesn't mean anything more than that.
3D Math is always relative to a reference frame, so when you say "forward" you really mean "forward relative to coordinate system X". In this case, force.AddForce is in world space but by default transform.Translate is in local space. If you called transform.Translate(Vector3.forward, Space.World) it would behave the way you expect.
Your answer
Follow this Question
Related Questions
Vector question 0 Answers
How to position an object using the w axis from Vector4? 1 Answer
Rotate GameObject 90 degrees where is my flaw? 0 Answers
Problem : Scale Object by distance 0 Answers