0 votes

I have an Area2d and I have multiple KinematicBody2ds. Some of them are in a group called "Enemy5" and Some are in a group called "Enemy9". Now I have a function in a script attached to the Area2d func Check(): and in this function I want to check how much KinematicBody2Ds which are in one of those groups are in the Area2d.

in Engine by (330 points)

1 Answer

+2 votes

You can use the signals: on_Area2D_body_entered() and on_Area2D_body_exited()

func _on_Area2D_body_entered(body):
    if body.is_in_group("Enemy9"):
        Enemy9_count + = 1
        if body.is_in_group("Enemy5"):
        Enemy5_count + = 1


func _on_Area2D_body_exited(body):
         if body.is_in_group("Enemy9"):
        Enemy9_count - = 1
         if body.is_in_group("Enemy5"):
        Enemy9_count - = 1
by (2,058 points)
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.