_On_Area2D_body_entered not working properly

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

I am making a 2D sidescrolling game. In the main scene, I have a KinematicBody2D called Player as my player and in a second scene I have an Area2D as my bullet called Bullet.

Shooting the bullet and deleting it when it goes offscreen works, but I tried adding a second kinematic body with a collision body and printing “Entered: [body name]” onto the console. However, when starting the game it prints “Entered: Player” and when shooting into the second KinematicBody2D, it does nothing.

Bullet function for collision detection:

func _on_Bullet_body_entered(body):
 print("Entered: ", body.name)

iirc body entered only signals when there’s a SomethingBody entering
there should be an AreaEntered or something similar for areas

1234ab | 2022-01-05 19:34

I tried this

func _on_Bullet_area_entered(area):

In the script for the bullet, still doesnt work though. Am I doing something wrong with the collision layers or is it not working because the Bullet scene is being instanced? Sorry if that doesnt make sense, I am a beginner (And yes I indented the function correctly, it just doesnt display here)

pion | 2022-01-05 21:24

hmmm, did you connect the signal? it should show something like a green arrow left to the function, if it is connected
there should be this Node tab on the left-top side where you can connect it
Using signals — Godot Engine (stable) documentation in English

acually the next doc seems to be kindof related too, it may be worth looking at it if you haven’t already https://docs.godotengine.org/en/stable/getting_started/step_by_step/your_first_game.html#doc-your-first-game

also, I dont know how people usually implement bullets, but I’m not sure an Area is the best, maybe they should be Bodies too (?)

1234ab | 2022-01-06 18:56

If the bullet scene is instanced at runtime via code, it’s not going to automatically connect signals to your kinematic body, you have to do that explicitly.

skysphr | 2022-01-06 19:08