Resetting position of player

Hi
I have created a basic HUD which allows me to move around my scene based on where the camera is pointing. This means I need to find a way to move my player back to its original position.

So I first get the position of the player which hosts the camera
7625590--948685--2021-11-03 (6).png

 public void Start()
    {
        coordsMarker = player.transform.position;
        Debug.Log("player coords for marker" + coordsMarker);
    }

but the coordsMarker values don’t match those of the original position of the player

I then plan to do this when the reset option is chosen in the hud

 player.position = coordsMarker;

is this the correct approach? Any ideas where I am going wrong?
thanks

Since you store the first player position in coordsMarker, what does coordsMarker contain and why do you think it’s not the position the player had at the beginning?
Maybe you change the position in some other scripts’ Start function which executed earlier in the execution order?
Or you overwrite the value later on?

thanks for getting back to me
because when I compare the values in transform when I run the scene they are different. I have tried moving the code to just before when I want to reset and get the same result. I have removed from start() to avoid confusion

Coordinates are:
In code, from debug:
player coords for marker(449.5, 152.2, 1225.5)
In editor
player starting position in editor when i launch the scene: -1.955032e-05,-2.861023e-06, 4.386902e-05

This is how my hierarchy is set up
7625590--948685--2021-11-03 (6).png
thanks

Check your parenting. If you have some parent A at position (100,100,100) and a child B at position (1,0,0), this refers to its local position inside the parent. It’s actual position will be global, meaning (101,100,100).

great thanks
this was one of the problems - also now understand how to subtract values from y axis - together these solved the problem

   player.position = coordsMarker;
            //move hud relative to the player
            playerPosition = player.position;
            huds.position = new Vector3(playerPosition.x, playerPosition.y - 5f, playerPosition.z);

thanks for your help

1 Like