Respawn and Checkpoints

How to create a player respawn and checkpoints

If your game is fraught with danger then chances are the player’s hero will die during your game. In most games, the hero will have more than one life and can continue the game (either from where they died, or more commonly, from a checkpoint). This tutorial explains how to create a respawn system in your game.

First, let me explain the difference between a create respawn and a revive respawn.

In a create respawn the hero will die, be removed from the game, and another hero will be created. All the stats that were recorded in the previous hero will be lost – including inventory items, any score, and skills information. You can get round this by recording all this information outside the character or use multibrain techniques to push the info back into your new hero character once created. However, all this is unnecessary as you have a far easier option: the revive respawn.

In a revive respawn the player reaches the point of death, but instead of dying they have their health revived. All their inventory contents, score, and other information are intact as they did not actually die and get destroyed. This is by far the easiest method, and the one I will be using for this tutorial.

In every instance you will need to set your hero’s brain properties/combat and defence destroy after death: off.

Basic Revive respawn

In your hero brain

WHEN [started to][is dead] DO [revive]

This will create an immortal character who will revive every time they die. This can be an issue when the reason they are dead at this spot is still present, which means they will die and revive in an infinite loop. A better option is to respawn them to a safe place (a checkpoint).

Revive with 4 seconds of invulnerability

You may want to give your player a chance to get away from a deadly situation and still revive him in the spot where he died. This kode will allow you to give your character a few seconds of invulnerability to get away. You could also make them non collidable as well – just add the true and false states for collidable underneath the ones for invulnerable.

In your hero brain

WHEN [started to][is dead] DO [boolvar:dying][equals][true]
WHEN [boolvar:dying] DO
…WHEN [countdown timer][3] DO
…/…WHEN [started to] DO [revive]
…/…WHEN [duration timer][4] DO [hologram]
…/…/…WHEN DO [invulnerable][equals][true]
…/…/…WHEN [else] DO [boolvar:dying][=][false]
…/…/…/…WHEN DO [invulnerable][=][false]

Single Position Respawn

First you need to choose your respawn position. The easiest way is to place a logic cube down and use that. It is invisible and non collidable and can be used as a marker.

WHEN [started to][is dead] DO [boolvar:dying][equals][true]
WHEN [boolvar:dying] DO
…WHEN [countdown timer][3] DO
…/…WHEN [started to] DO [position][equals][IWP:logic cube][position][above]
…/…/…WHEN DO [revive]
…/…/…WHEN DO [boolvar:dying][equals][false]

Checkpoint Respawn 

Same as above, except the player either activates which respawn position he wants when he dies by activating the checkpoint, or the checkpoint is activated automatically using sensors. You can use bump or interact, see or use in trigger zone to activate the checkpoint. You can add kode to make it glow or change colour to indicate it is an active checkpoint.

WHEN [power on] DO [play fx][sparkle][on][me]

Checkpoint kode

WHEN [bump][player] DO [global][objvar: respawn point][equals][me]
…WHEN DO [power on]

For the default checkpoint (the first one where the player will respawn if they haven’t activated any checkpoints) add this extra line.

WHEN [once] DO [global][objvar: respawn point][equals][me]
…WHEN DO [power on]
WHEN [global][objvar:respawn point][not equal to][me] DO [power off]

Set number of lives

You can limit the amount of times a player will revive in this way, and give him “lives”. You should always show this symbolically on screen so the player can see how many lives they have left.

WHEN [started to][is dead] DO [boolvar:dying][equals][true]
WHEN [boolvar:dying] DO
…WHEN [numvar:lives][>=][1]
…/…WHEN [countdown timer][3] DO
…/…/…WHEN [started to] DO [revive]
…/…/…/…WHEN DO[numvar:lives][decrement by][1]
…/…WHEN [else] DO [boolvar:gameover][equals][ true]
…/…/…WHEN DO [boolvar:dying][equals][false]
WHEN DO [display][text:lives: ][numvar:lives][screen top right]


Comments are closed.

Website Powered by

Up ↑

%d bloggers like this: