`RigidBody2D` does not trigger `body_entered` signal when a `CharacterBody2D` enters it

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

I am making a mechanic of a Character collecting Apples. My Character is using a CharacterBody2D . Both of the Nodes have a Sprite2D, AnimationPlayer and CollisionShape2D

My Apple is using a RigidBody2D with the following settings:
Freeze: On
Freeze Mode: Static
Contact Monitor: On
Max Contacts Reported: 1

Inside my RigidBody2D apple I added a function that connects to the body_entered signal

func _on_body_entered(body):
    print("add code to make apple disappear")

It doesn’t trigger this function and the character just passes by the Apple. What am I doing wrong?

:bust_in_silhouette: Reply From: aidave

Add an Area2D on the player, and connect the body_entered signal there to detect apples. This will give you better configuration possibilities.

Otherwise you may have to use get_slide_collision() which is more complicated

You’ll want to learn Physics Layers and Masks and understand those. And also Groups can be useful here (ex: apple is in group ‘pickup’).

Thank you! I would like the logic to be on the apple so I can control the behavior of the apple based on whatever hits it. If so, should I just put the Area2D on the apple?

geocine | 2023-03-17 13:50

Yes, you could do that

aidave | 2023-03-17 14:26