This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I have an enemy I'm working on, and I'm trying to make him lose health when my bullet hits him. I connected the body_entered signal from the enemy's area2D node to the root node of the enemy which is a kinematic body 2d. However it's completely ignoring my bullet, but if i make my player jump into it it works. my bullet is in a separate scene and is being instanced in. It is an area2D with a collision shape. What am I doing wrong?

in Engine by (391 points)

I think a body entered signal should be on the bullet, it is an area and the target is a body , a body is entering the bullet and area is entering the enemy. when I have a problem like that I will put a print statement with the body entered function that receives the signal to check if a signal is being received, for me I usually have layers wrong.

this is how it looks in my project.

func _on_Bullet_body_entered(body):
  explode()
  if body.has_method("_take_damage"):
    body._take_damage(damage)

the bullet checks the body that entered its collider for a function 'take damage' and delivers the amount of damage for that bullet. it comes from KidsCanCode Top Down Tank tutorial

I tried it, and it worked! thanks! :)

it did not work the first way because the bullet is an area and the enemy was waiting for a body to enter.

oh, so either a kinematic, rigid, or static body?

yes, it is not the type of the bullet node it is the signal on>>body<< entered , that means that a body entered the enemy not that the enemies body was entered. but unless you are making a bullet that bounces an area is the right choice . the script is better off in the bullet because it is the bullets function, to deliver damage, it works the same for things like a health pick up , its function is to deliver health , that adds up to simplify the enemy and player scripts and give better organization to have the player/enemy be accessed by what ran into them (or they ran into) rather than making the enemy or player script sort that out.

1 Answer

0 votes

Hi, try to use func _on_Bullet_area_entered(area) but first make sure you have create a area2d node in the bullet scene.

by (55 points)

I did that, using ArthurER's method, but i'm curious, why doesn't it work the way i tried first? Is it because the bullet is instanced in the scene?

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 Frequently asked questions and 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 [email protected] with your username.