Respawning Mechanic

Respawn Concept

Currently the goal is that if a player dies, he respawns after a set amount of time. Now the idea is simple. But the implementation is easier said than done.

Implementation

Our game is a PUN multiplayer so we need to be very careful on how to implement this without causing issues for other players.

Key things to note:

  • What to Disable/Enable:

Which aspect of the player to enable and disable and on which client. If a player dies and needs to respawn, only the player effected should disable his movement and character scripts. Whereas when it comes to meshes, all players must disable that on the specific player.

  • Syncing Transform Positions

All players need to disable the transform view of photon on that specific and re enable it on respawn of that player to avoid transform position issues (De-sync issues). The transform should also notify all other players where they respawned.

  • Syncing Animations

Only the local respawning player needs to disable and enable their animations. All the other clients will have it automatically synced up if the photon animator view is on.

Key findings

Even with all of the above points noted, trying to implement it is a whole different beast. Code itself is quite small for it.

The biggest issue was animation syncing. The local player gets the correct animations for their player when respawning but all the other clients see a stiff body moonwalking which is obviously not intended. Photon animator view was not correctly syncing up the animations even after respawn. In the end, the animator never have to be disabled, and the controller should remain enabled on other clients even if they did not need it.

After Respawn

Once the animation issue was resolved, it was time to move on to the actions that come after it. Such as telling the demon that this person is alive again. Resetting player UI for health and abilities and giving back control to the player, removing the low health colour adjustment (Post processing effect), as well as using the same healing vignette on respawn for that set amount of duration.

0
Subscribe to my newsletter

Read articles from mian mohammad shah directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

mian mohammad shah
mian mohammad shah