|Topic was automatically imported from the old Question2Answer platform.
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.
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!
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