Confusing with transform.position and transform.localposition in the 2.5d view


I have a scene that contains a main camera rotated with Z=27 and many ROADS, Above the ROAD we have an obstacle the view is like the image :

Obstacle Holder Script :

public class ObstacleHolder : MonoBehaviour
    public Vector3 transformPosition;
    void Update()
        transform.position = transformPosition;


I noticed that when i change the transform.position.x the obstacle moves horizontal on the x axis like the green axis image and the x and y of the transform.localposition change to make the obstacle move inside the roads can any one explain me why transform.position move like the green image and localposition move like the red image ?

I would like to understand more what is transform.position and transform.localposition in this case.

I know that :

Transform.position is The position of the transform in world space.

Transform.localPosition is Position of the transform relative to the parent transform.

but i don’t understand what does it mean in this example i am confusing with that

the project is here


Your obstacles are parented to your camera, and as such their local coordinates are relative to it.

Originally your camera X and Y axes were aligned to world axes. But now that your camera is rotated around Z axis in world coordinates, whatever children of your camera, “inherits” the camera space. That is to say, no matter your camera rotation, its children will always lean to the camera left side when you move them towards the left by offsetting their “local position”. If you simply offset their “position” to the left, they would go left relative to world space instead. Same applies to rotations and scale.

EDIT: So I guess either unparent your obstacles from the camera or make sure you use the right coordinate space.