The player starts with 3 lives. Each time they touch a danger (spikes, an enemy…), they lose one and the health bar goes down. At 0, it's Game Over: the level starts again.
You need:
- a character named player that can move (see Move a character);
- one or more dangers, for example red squares named spikes1, spikes2…;
- a health bar: a ProgressBar object (progress bar) named healthBar, at the top of the screen.
Step 1: prepare the dangers and the bar
- Select each danger and type danger in its “Tag (Label)” field.
- Select healthBar. In the inspector's “PROGRESS BAR” section: Minimum Value = 0, Maximum Value = 3, Current Value = 3.
Step 2: create the “vie” variable
- In the left panel, Variables section, create a variable.
- Name: vie (health) · Scope: Local · Type: Integer · Starting value: 3.
Step 3: lose a life
- Open the scene's Blueprint.
- Add the “If object touches Tag” event: target player, Tag danger.
- Add “Add to Variable”: variable vie, Value to add = -1 (with the minus sign, to subtract).
- Add “Set Progress”: target healthBar, New progress =
=vie - Link the three nodes in order.
If object touches Tagtarget: player · Tag: danger
→
Add to Variablevie · - 1
→
Set ProgresshealthBar · =vie
👉 Writing
=vie in “New progress” means: “take the value of the vie variable”. So the bar always follows the number of lives.Step 4: Game Over
- After “Set Progress”, add the “Condition” node with Condition =
=vie <= 0(“vie smaller than or equal to 0”). - Link its True output to the “Restart the scene” node (category Scene & HUD).
- Save, start the game and touch a danger three times.
Set ProgresshealthBar
→
Condition=vie <= 0
True →
Restart the scene
👉 “Restart the scene” puts everything back as it was: objects in their place, and Local variables (so vie = 3) back to their starting value.
👉 Want a real end screen? Instead of restarting straight away, link the True output to “Modify Text” (a “You lose!” text), then “Wait” (2 seconds), then “Restart the scene”.
Bonus: falling into the void
For a platform game, put a Zone object at the very bottom of the scene, named fallZone (a zone is invisible during the game). Then:
Collision A/BObject A: player · Object B: fallZone
→
Restart the scene
If it doesn't work
- Health doesn't go down: check the danger tag on each danger, and the minus sign in -1.
- The bar doesn't move: the target of “Set Progress” must be a progress bar, with a maximum of 3.
- The game doesn't restart: the condition must be linked through its True output.