Platformer Tutorial, Part 7: Make Enemies Kill the Player (and the Player Kill the Enemies)

This part of the tutorial explains how the player can kill – and be killed by – the game's enemies.

Series

Step 1: Kill the player

When the player collides with an enemy, the player should die. An easy way to “kill” the player is to delete the “Player” object if it collides with an enemy.

To delete the “Player” object if it collides with an enemy:

  1. Create a new event.
  2. Add a Collision condition that checks if the “Player” object is colliding with the “Slime” object.
  3. Add the Is on floor condition to the “Player” object. This ensures that the player only dies if they're on the platform (i.e. not jumping).
  4. Add the Delete an object action to the event that deletes the “Player” object.

If you preview the game, running into the enemy will kill you.

Step 2: Kill the enemy

If a player jumps on an enemy, the enemy should die. Similar to the previous step, “death” in this case means deleting the “Slime” object.

To delete the “Slime” object when a player jumps on it:

  1. Create a new event.
  2. Add a Collision condition that checks if the “Player” object is colliding with the “Slime” object.
  3. Add the Is falling condition to the “Player” object. This ensures that the enemy only dies if the player is jumping (i.e. not on the platform).
  4. Add the Delete an object action to the event that deletes the “Slime” object.

If you preview the game, you can jump on the enemy to kill them.

(Optional) Step 3: Bounce on the enemy's head

In a lot of platforming games, when the player jumps on an enemy, the player bounces on the enemy's head. This is makes killing an enemy feel more fluid.

To make the player bounce on the enemy's head:

  1. Add the Allow again jumping action to the “Player” object.
  2. Add the Simulate jump key press action to the “Player” object.

If you preview the game, you'll bounce on the enemy's head when killing them.

Next step