Choosing destinations – respawn to the most recently passed checkpoint
A checkpoint usually represents a certain distance through the game (or perhaps a track) in which an agent (user or NPC) has succeeded reaching. Reaching (or passing) checkpoints often results in bonus awards, such as extra time, points, ammo, and so on. Also, if a player has multiple lives, then often a player will be respawned only back as far as the most recently passed checkpoint, rather than right to the beginning of the level.
This recipe demonstrates a simple approach to the checkpoints, whereby once the player's character has passed a checkpoint, if they die they are moved back only to the most recently passed checkpoint.
Getting ready
This recipe builds upon the player-controlled 3D cube Unity project that you created at the beginning of this chapter. So, make a copy of this project, open it, and then follow the steps for this recipe.
How to do it...
To have the respawn position upon losing a life change depending...