Create Your First Godot 4 Game

Lesson 8: Handling player death

Video Notes

Our player has to meet their end at some point. In this lesson, we’ll handle the player dying.

  • AdamDee
    Nov. 21, 2022 at 12:21 p.m.

    Instead of making a new node for ground, can’t we just use the PlayArea node and have it signal when player body exits?

    • amit
      Nov. 21, 2022 at 3:26 p.m.

      Yes, I think that would work and it would be simpler too. Just make sure you set the CollisionShape’s mask for the PlayArea to collide with the Player as well. Good find!

    • SpaceKitty
      Dec. 18, 2023 at 1:57 p.m.

      Oh yeah! That seems a much more straight forward solution, thanks for that!

      • DarkFilter
        Jan. 25, 2024 at 3:17 a.m.

        i tried this and i got it to work when the player exits the screen, however after an enemy collision the game crashes

        • amit
          Jan. 26, 2024 at 9:51 p.m.

          Can you provide a little bit more information about the crash? What line does it crash on and what’s the error message?

  • JTW789
    Sept. 24, 2023 at 4:03 a.m.

    The camera keeps following the player after they fall. How do I fix that?

    • amit
      Sept. 25, 2023 at 2:47 p.m.

      In the player’s _process() function, we have:

      func _physics_process(delta):
        # ...
         if active:
           camera.position = position
        # ...

      and in the player’s die() function:

      func die():
        # ...
        active = false

      So we only move the camera when the player is active and we turn off the active flag when the player dies.

  • dkgsblotch
    Oct. 19, 2023 at 8:16 a.m.

    in this video we created a signal called "game_over " and we emit it in the function _on_player_died but i dont see which script is listening to this signal

    • amit
      Oct. 19, 2023 at 1:52 p.m.

      The game_over signal doesn’t actually get used. I think Tom had some ideas that we had to cut from the tutorial and this might be left over from that. So you can safely omit that signal. Good catch!

  • LeGrandFromage
    Oct. 29, 2023 at 10:01 p.m.

    The corrections section for this lesson mentions ammo and shooting, but that doesn’t get implemented until the next lesson.

    • amit
      Oct. 30, 2023 at 6:18 p.m.

      This has been fixed – thanks for pointing that out!

Want to get into the mix? Sign in or register to comment.

Next lesson