- Home /
Different between transform.Translate() and Vector3.MoveTowards?
I want to move an object in a straight line during every frame. I noticed that there are two functions (not rigidbody-based) that can achieve this:
transform.Translate(Vector3.up * Time.deltaTime * speed)
and
transform.position = Vector3.MoveTowards(transform.position, transform.position + new Vector3(0,1,0), Time.deltaTime * speed)
What exactly is the difference between these two?
Answer by Captain_Pineapple · Jul 15, 2018 at 09:12 PM
transform.Translate() should apply movement relative to the transform itself, except if you define that you want to move in worldspace coordinates or any other transform cooridnates. See also the Manual for exact reference and usage.
Vector3.MoveTowards() will only translate a vector by a given direction and stepsize. This can be handy if you want to calculate positions without a specific transform.
Thus in your example the result should NOT be the same when applied to a transform that is rotated by any means s.t. the y-Axis is not pointing upwards.
Hope this helps!