Problem with body_entered signal

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fago

Hi,
I need help with the body_entered signal of an Area2D node.
In my game I can break an Item with the Sword or with a Projectile. This Item is made like this:

Area 2D

  • Sprite
  • AudioStreamPlayer2D
  • CollisionShape2D
  • StaticBody2D
  • CollisionShape2D

While Sword and Projectile are made like:

KinematicBody2D

  • Sprite
  • AudioStreamPlayer2D
  • AnimationPlayer
  • CollisionShape2D

and:

KinematicBody2D

  • Sprite
  • AudioStreamPlayer2D
  • CollisionShape2D

The Item uses the body_entered signal. It detects the Sword, that appears when its button is pressed and plays the animation, while it doesn’t see at all the Projectile, which is moved with move_and_slide(): they collide, but the signal doesn’t get triggered. If I delete the CollisionShape2D node inside the StaticBody2D of the Item, the Projectile passes trough it and signal gets triggered. But I want the Item to be “physical”.
Does anyone know what the problem could be?
Thank you very much!

I solved this with a custom signal in the Item. When the Projectile collides, I take the collider and if this is the Item, I emit the signal.
Anyway, I mantained the other code for the Sword (inverting Area2D and StaticBody2D).

fago | 2018-06-06 21:15

:bust_in_silhouette: Reply From: fago

I finally got it: I made the two CollisionShape2D inside the Area2D (Item) identical, but the one inside the StaticBody2D has to be significatilly smaller than the other one.
Anyway, in my case the workaround I found works better.