Area 2D is ignoring my bullet.

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

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?

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

ArthurER | 2020-10-03 03:58

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

Millard | 2020-10-03 17:39

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

ArthurER | 2020-10-04 00:14

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

Millard | 2020-10-04 04:09

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.

ArthurER | 2020-10-04 05:42

:bust_in_silhouette: Reply From: Simon

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

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?

Millard | 2020-10-03 17:40