How To Get Name of Colliding Node

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

I have 2 kinematic 2d bodies. One for bullet and one called Zombie. I want to know when the zombie is colliding with the bullet so i can reduce its life but i can’t find function to get the name of colliding body

I ll apreciate if u help me :wink:

Are you using an area2d to check for the bullet or a different way?

Asthmar | 2021-07-17 17:47

:bust_in_silhouette: Reply From: vnmk8

you can use an area node attached to the bullet node and connect it’s signal when a physics body enters it, the signal’s function has a body parameter that is the reference to your zombie or any colliding physics body, then you can access a function inside the zombie script:

func _on_myBulletArea_body_entered(body):
  if body.is_in_group("zombies"):
      body.reduce_health()