I’m going to jump my player to a new position in the level when I pause the game, which I will use as the pause screen/room, and I want to store their current position and direction as I press pause so when I resume the game they will be in the same place and facing the same way they were when I pressed pause, even if I move and turn around while in the pause screen/area.
So how do I store and set the player’s direction properly?
I’ve tried using the following when the pause button is pressed down:
if (!gamePaused)
{
playerStoredPosition = player.transform.position; // Stores the position of player in the level
playerStoredDirection = player.transform.forward; // Stores the forward direction of player in the level
player.transform.position = playerPausePosition; // Jumps player to pause position (set in Start)
player.transform.forward = playerPauseDirection; // Turns player to pause direction (set in Start)
gamePaused = true;
}
else
{
player.transform.position = playerStoredPosition; // Returns player to stored position
player.transform.forward = playerStoredDirection; // Returns player to stored direction
gamePaused = false;
}
But it’s not working.
The storing of the position works fine, but when I resume the game the direction the player is facing is wherever I’ve turned when in the pause room rather than where I was facing when I actually pressed pause.
Any ideas how to get this to work properly?