Respawn after player is inactive for a certain time

Hi all,

fairly straight forward - I’m looking for a way to get my player to respawn after being inactive (not moving) for a certain amount of time. I’m making a game in which the player explores a terrain, and this will be shown in a public space - ideally, if someone explores for a while and then stops, I’d like the character to respawn so that the next person to come to the game starts from the beginning. I’ve successfully used scripts to respawn characters if they fall off the terrain, but I’m new to script writing and am not sure where to start with this one.

Thanks

Use a timer and check for input, if none count the timer up until max time, respawn

I recommend using this in a simple if statement with the timer.

if(!Input.anyKeyDown)
{
    timer += Time.deltaTime;
    if(timer > respawnTime)
    {
        Respawn();
        timer = 0;
    }
}

Interesting idea, this would respawn the player after x seconds of inactivity, but if the player lets say plays for 1min and 30sec and the next player starts to play, the max timer is set to 2 min, the second player will only be able to look and do nothing for 30 seconds, I would just let the counter count up and reset it whenever there is any key pressed, but it depends on the wanted situation.

True, it was more about the example with anyKeyDown.
But you are 100% correct this would give incorrect behaviour when the second player enters.

You could check for input afterwards and start the timer only when a button is pressed after the player has started moving. aka a new player has arrived