Collisions with a Character that has Multiple Areas

Godot Version

4.3

Question

Hey all, I have a question about collisions with a character that has multiple areas on them. Right now my goal is to make a character that would have multiple hurtboxes that represent a different part of the body. For example, the character would have a hurtbox for the head, body, arms, legs, etc.

The part that is tripping me up is how I would handle collisions with multiple hurtboxes at a time. In my game, if I shoot the character just right, I am able to hit two hurtboxes at the same time. This cause each hurtbox to run it’s take_damage() function, so the character essentially gets dealt double damage.

So my questions is, what would be the best way to handle this interaction? How would I be able to process only one collision while discarding the other one? Would there be a way to have some sort of hurtbox priority?

Right now, all my collisions are just areas just interacting with each other.

Let me know if you have any suggestions or if I should try something totally different. Thanks a lot!

You could put multiple collision shapes under one hitbox area and if need be, get the local shape index for that collision shape.

1 Like

Unfortunately, that doesn’t seem to work, unless I am doing something completely wrong.

If I have the multiple shapes under an area, I can only parent the area to one bone. So if i had multiple shapes for the whole body, the whole body would move with just one bone.

Im unable to do it the other way, if I have an area, with BoneAttachment3Ds in side them, that would give me an error since BoneAttachment3Ds must be a child of a skeleton.

This is form what I tested out, unless i am totally wrong.

Ah I see what you mean. You may have to use a debounce style variable

var hit_debounce: bool = false

func on_hit() -> void:
    if hit_debounce:
        return

    hit_debounce = true
    # do damage calculation

    await get_tree().process_frame
    hit_debounce = false

Hey all, i just wanted to post a solution that I found in case anyone else has this problem in the future.

What I ended up doing was making an AreaManager node that would be in charge of processing the order of collisions based a priority value that I assigned to each Area.

The gist of the idea is this:
Each Area has it’s priority set (I had to make my own priority value since areas already have one) and then in the ready() function I connect the area_entered signal to a function that will add the area to a group.

The AreaManager has its Physics Priority set to a large number, this will ensure that it will run its physics_process() function after each collision with an area occurred. Then it will then store the nodes in the group in an array. If the array is not empty, the array will be sorted based on the highest area priority. Then after that I do what ever I need the first area to do, in my case use the area as a hurtbox to take damage. I then just remove any nodes in the group and that is it.

Hopefully someone finds this useful. If anyone has any suggestions too please let me know!

1 Like

I dunno, I’d just call that a critical hit!