#Can't get collision to work in one particular case

1 messages · Page 1 of 1 (latest)

ancient hearth
#

I don't know what's different in this case, as I've got a decent understanding of godots signals and physics layers/masks, but this one isn't working. I'll try to illustrate what I have

  • I have a player. The players attack produces a thrown weapon that has a StaticBody2D. The weapon becomes active for the duration of the attack. The weapon is in the PlayerWeapon physics layer. It has the Enemy physics mask

  • I have an enemy. The enemy has an Area2D. The enemy has a script with the _on_body_entered signal that should print the body that entered. The enemy is in the Enemy layer, and has the PlayerWeapon mask

The signal does not get fired when the weapon hits the enemy. If I mess around with the layers/masks, I can get the enemy Area2D to interact with the player and environment layers. It's just these 2 layers in particular that won't interact with each other

The layers are
1 - environment
2 - player
3 - enemy
4 - playerWeapon

lavish trellis
#

i can't help much at the moment but a quick tip is to enable collision debugging from the top debugging menu of the editor. the collisions shapes should change color when they detect a collision and they will also be visible at runtime

ancient hearth
#

yep, I have that setting turned on

storm crystal
#

Also, if the weapon is moving it shouldn't be a static body

ancient hearth
#

I did not, and yea that's a good point. I originally had it as just an area2d but saw that that doesnt inherit physicsbody2d so i thought that was the issue

storm crystal
#

Characterbody or AnimatableBody for moving bodies, but if you don't want any collision, just detection area will be fine

#

.. then you need your area to detect other areas( I think it's in by default ) and use the area_entered signal instead

ancient hearth
#

ok, changed my enemy to a characterbody2d, and the weapon to an area2d, and I can hook up a signal for the weapon

#

so I guess I maybe went down the wrong path as I wanted my enemy to detect getting hit, not my weapon detecting the hitting. The characterBody2D doesn't have any such signals from the looks of it

#

but maybe from a design standpoint the weapon should do the detecting? Then call some sort of inherited method on the enemy to do damage/effetcts?

#

If I want the enemy to detect getting hit then I'd need to add an area2d it, which seems kind of strange as I already have a collisionShape required for the characterBody2D. It feels to me that I should be able to detect collisions with that

lavish trellis
#

it depends on your intentions. if for example you are making a split attack damage it makes sense to apply the damage to enemies from within the weapon (which knows how many enemies the damage should be split across)

but having the enemies detect the hit also makes sense for its own thing.

using 1 collider for hit detection and another for collision detection is not redundant imo.
especially if you set a different layer for hitboxes and hurtboxes seperate from your environment