0 votes

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 onbulletbodyentered(body):
if body.isingroup("enemy"):
sprite.play("collide");
collision.setdeferred("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?

in Engine by (26 points)

1 Answer

+1 vote

you don't need the first line of the function
you can use collision layers and collision masks:
https://www.youtube.com/watch?v=AyzMkCWaB1c&t=1506s

by (290 points)

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

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.