Quick transformation question.


I can’t get my head around transformation as good as I want so let me ask a quick question but be thorough as you want with the answer:

transform.Translate(Vector3(0,0,speed) * Time.deltaTime);

identical to
transform.position += Vector3(0,0,speed) * Time.deltaTime;



Translate moves along local axes (by default, but can be changed to world axes).
Changing position moves along global axes (but there are functions to convert to local axes).

No it is not equivalent. I believe omitting the Space paramater (Unity - Scripting API: Transform.Translate) will cause the translation to default to local space rather than World.

In this following line of code:

transform.position += Vector3(0,0,speed) * Time.deltaTime;

you are modifying world position.

To make them equivalent you would have to do:

transform.Translate(new Vector3(0,0,speed * Time.deltaTime), Space.World);

I think you can easily test this my replacing Time.deltaTime with a constant, so that you can reverse it and then apply the second method. Something like:

transform.Translate(Vector3(0,0,speed)* 0.3); // apply method 1
Debug.Log(transform); // results of method 1
transform.Translate(vector3(0,0,speed) * -0.3); // reset

transform.position += Vector3(0,0,speed)* 0.3; // apply method 2
Debug.Log(transform); // results of method 2

Comparing the results should give you the answer you want. However, even if there were identical (you’ll find that they’re not), the overload method of Translate that holds the advantage is the one with the RelativeTo parameter which will translate relative to something else. You can see the documentation here: http://docs.unity3d.com/Documentation/ScriptReference/Transform.Translate.html

Hope this helps!