Collider conflicts

Godot Version

4.2.1

Question

Hey, everybody! I had a problem with the character death mechanics. On the first scene everything is normal, but on the second scene, the collider (as I understand it) conflicts with the player’s collider. I have death mechanics arranged so that there is area2d (plus the collider), it is connected to the player, when the player touches it, the scene is reloaded.


Hi there, your question is a little difficult to answer in its current state

  • What’s the issue you’re facing? How would I go through step by step to recreate the issue? I’m not really sure what the “first” and “second” scenes are here, or what “conflict” means in your case. In your video the only thing wrong I see is the “player death” print message happening continually after you hit an enemy.
  • You’ve got several giant code chunks you screenshotted. It’s good practice to put them in a code block instead for readability, and omit any code that’s not relevant. The only relevant code I see here is:
func _on_death_arena_body_entered(body):
    print("Player Death")
    get_tree().reload_current_scene()

But given that hunch, my bet is that your issue lies with whatever is triggering the _on_death_arena_body_entered function. So I’d look at your collision areas and their properties in the scene.

There are two scenes, LVL01 and LVL02 (they are shown in the video). On LVL01 and LVL02 there is an Area2d with a collider and a sprite, the death mechanic works so that the player touches the item and the scene reloads . LVL01 everything works fine, player touches, player dies (this is just the part of the code you showed). But in LVL02 the mechanics does not work like that, the player spawns and immediately dies without touching the object. The scenes are different, but the settings are the same. Initially I thought it was because of the colliders, like the script considers the player’s collider as a death zone, but then why does it work fine in LVL01? Now I don’t understand anything at all… :face_with_diagonal_mouth:

In your second level, try putting a breakpoint on your _on_death_arena_body_entered function and look at the call stack. That way you can determine what is “killing” the player.

I’d also point out in that video that continuously after the player first touches the enemy, the death message is printed over and over again each frame. I imagine that could explain the constant death issue you’re seeing.

1 Like

For my first stab at death logic, I realised death actually needs to last a number of frames, during which time the player is dying, and can’t be killed again. To stop enemy colliders from killing my player on every frame their collider touches the players, I put something like the following in place:

_die() -> void:
    if not _is_dying:
        _is_dying = true
        _show_death_animation()
        _play_death_sfx()
        _do_other_death_stuff()
        await self.player_died

When I then reset the scene, I have some code along these lines:

_reset() -> void:
    # Do some  prep stuff
    _is_dying = false

I can then use _is_dying in the player class to change their behaviour accordingly. For example, I still have gravity affect them when dying, but I don’t have them collide with springs and other entities.

1 Like