MysticalUser
MysticalUser

Reputation: 414

What is the use of transform.Translate()?

What is the difference between doing

transform.Translate(offset);

and

transform.position += offset;

Is there any smoothing or stuff in the background that the method is doing or is it just

public void Translate(Vector3 distance)
{
    this.position += distance;
}

Upvotes: 1

Views: 1076

Answers (1)

Ruzihm
Ruzihm

Reputation: 20249

transform.Translate(offset) moves by offset in local space. In other words, it takes the rotation of transform into account

transform.postition += offset moves by offset in world space. In other words, it does not take the rotation of transform into account.

Otherwise, they are the same. You can think of transform.Translate as:

public void Translate(Vector3 offset)
{
    this.position += this.TransformDirection(offset);
}

See transform.TransformDirection for more information.

transform.Translate(offset, Space.World) would be the same as transform.position += offset

Upvotes: 3

Related Questions