0 votes

So, I have a KinematicBody2D with Area2D and I use it to detect enemies who enter the detection radius of the body. Here's the code for the signal:

func _on_Detection_area_body_entered(body):
    enemy = body

Problem is that if there's another body behind the first one it'll react to it and enemy will be equal to the new body. I still want to detect the first enemy, kill it and only then switch to the second one. I tried many other ways (this is the first one) and none of them work.
Any idea how to do it?

in Engine by (32 points)

1 Answer

0 votes
Best answer

Well, you can use another variable to use as a queue for the enemies that come after the first one, that way you always get the first enemy selected and all the other enemies registered in an organized way

by (1,190 points)
selected by

I've just tried that, but when I kill the first enemy soldier just doesn't react because area2d doesn't update.

P.S. Just fixed that by modifying thearea_body_exited. Thank you!

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.