0 votes

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)
Godot version 3.4.2
in Engine by (18 points)

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

I tried this

func _on_Bullet_area_entered(area):
print("Test")

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)

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
https://docs.godotengine.org/en/stable/getting_started/step_by_step/signals.html

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 (?)

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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.