Bullet collides with multiple objects

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

Whenever my player shoots a bullet and it reaches the enemy, it collides with more than 1 enemy. The bullet node is an Area2D, and the enemy node is also an Area2D (it used to happen even when it was a a KinematicBody, i changed it for other unrelated reasons)

My guess is that the bullet enters the collision shapes of multiple enemies, and since the collision detection is slower than other processes, it doesn’t get detected instantly to prevent such a thing from happening.

The code is:

func _on_bullet_body_entered(body):
if body.is_in_group(“enemy”):
sprite.play(“collide”);
collision.set_deferred(“disabled”, true);
vel = Vector2();
body.damage(bullet_damage);

damage is a function at the enemy node’s end.

Is there a faster way to detect bullet collisions/ a way to speed up body_entered signals?

:bust_in_silhouette: Reply From: mdubaisi

you don’t need the first line of the function
you can use collision layers and collision masks:

You’re right, I blanked out there. I’ll see if it helps speed up the process.

strive_and_conjure | 2020-08-10 05:57