Area2D question (I am a starter, so for you it is very easy to answer me)

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

I have 2 KinematicBody2D (A and B) and one Area2D. If body A entered the Area2D, I want to print “Body A entered”. If body B entered the Area2D, I want to print "Body B entered.
Thats like the scene looks:

-Main
–AKinematicBody2D
–BKinematicBody2D
–Area2D

I already know how to conect the body_entered signal with another node, but I do not know how to differentiate between the two bodys,

Thanks for your answers!

:bust_in_silhouette: Reply From: Asthmar

If your familiar with groups, put each kinematic body in its own group. And then when you check for a body enter do something like

if body.is_in_group(B) print : (body b entered)

if body.is_in_group(A) print : (body A entered)

Hope that helps

I put them in a group, but when I trie to do this in the main scene:

func _on_Area2D_body_entered(body):
if body_is_in_group(A):
print(“A”)

There comes this: A is not declared in the currant scope.

Godot_Starter | 2020-02-14 18:03

Make sure to put quotations like this

if body.is_in_group(“A”):

let me know if that fixes it

Asthmar | 2020-02-14 18:53

It did fixed the proplem :slight_smile:

Godot_Starter | 2021-04-28 10:31

:bust_in_silhouette: Reply From: Newby

If you named your KinematicBody2Ds A and B respectivly you can try getting the name from them.

func _body_entered(body):
    print("Body " ,body.name, " entered")

It works and it is very simple

Godot_Starter | 2020-02-16 11:46