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
You are reading Part 7 of the Platformer Tutorial.
- Part 1: Getting started
- Part 2: Create a Playable Character
- Part 3: Create Platforms
- Part 4: Animate the Playable Character
- Part 5: Add Collectible Coins to the Game
- Part 6: Add Enemies to the Game
- Part 7: Make Enemies Kill the Player (and the Player Kill the Enemies)
- Part 8: Add Checkpoints to the Game
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:
- Create a new event.
- Add a Collision condition that checks if the "Player" object is colliding with the "Slime" object.
- 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).
- 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:
- Create a new event.
- Add a Collision condition that checks if the "Player" object is colliding with the "Slime" object.
- 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).
- 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:
- Add the Allow again jumping action to the "Player" object.
- 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.