hi

wondered if you can help, i have an issue with detecting collisions when a bullet is fired. i have an area2d bullet and a KinematicBody2D enemy

I'm just moving the bullet with position += velocity and the kinematic with move_and_slide detecting collisions with the

all is fine until the speed is increased, I obviously doing something wrong, way do Area2D collisions miss when object too fast?

is there a better way? i have I got some setting missing etc. please help

Might it be moving faster than your physics fps enables it to detect?

Cool, so is the solution either a faster fps or slower bullets

I might suggest using a simple RigidBody node on a separate physics layer, that way you can move it and take advantage of continuous collision detection (CCD) for fast moving bullets. As long as the RigidBody is on a separate layer from the other physics, it shouldn't be detected by other nodes in the game.

Or, depending on how your game is setup, you might be able to replace the Area2D with a Raycast2D, where the length of the raycast is the speed the bullet will move at, and the direction it points is the direction the bullet is going towards. The only issue with using a Raycast2D is that you lose the width of aspect of the bullet, but depending on your game and the size of the bullets, it might not be noticeable. Additionally, you could use multiple Raycasts2D nodes with a short distance to get the 'width' of the bullet.

The issue it sounds like the Area2D is having is collision tunneling, which is sadly an issue with almost every physics engine. Without it, performance suffers, but it can be problematic for fast moving projectiles.

Understood, shouldn't be an issue, I'll stick to the slower bullets. but it's nice to know the other options, thanks.

@Sparrow said: Cool, so is the solution either a faster fps or slower bullets

In that case, potentially either or both could help, but you could also look at the average fps and use that as a value to scale the bullet along the local axis that it travels, thus making it bigger and thus increase the detection chance. This way your bullet would effectively look to have motion-blur too.

@Megalomaniak said:

@Sparrow said: Cool, so is the solution either a faster fps or slower bullets

In that case, potentially either or both could help, but you could also look at the average fps and use that as a value to scale the bullet along the local axis that it travels, thus making it bigger and thus increase the detection chance. This way your bullet would effectively look to have motion-blur too.

sounds good thanks

3 years later