Why we used tranform.localPosition instead of transform.Position?

in the Move player using input system lecture

Hi Hasan,

localPosition refers to the position of the game object while position refers to the origin of the world.

Let’s say our camera is at position (99.123f, 23.234345f, 53.34983475f), and we want to move the spaceship 3 World Units (WU) to the left relative to the camera. All we have to do is to set the localPosition.x to 3 (plus an offset on the z-axis, so the spaceship is in front of the camera).

If we set the position.x to 3, our spaceship our spaceship would disappear from our game window because it is not in front of the camera anymore.

To make the spaceship visible with position, we would have to take the camera position, subtract 3 from the x-coordinate, and calculate an offset so the spaceship is in front of the camera. Take a look at the camera position. Would you want to calculate those things? I wouldn’t. localPosition does exactly what I need.

For reasons of convenience and because Unity provided this solution, we use localPosition in the Move method.

Is this what you wanted to know? :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms