This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I was messing around with high speed bullets (not high enough to be raycasts) and collision detection is a bit off. They are always registered, but sometimes at the wrong place in the object (say I shoot a wall, the collision position is set inside the wall instead of its border).

Upping the Physics fps to 240 kinda fixes this, but I was wondering if there's any downside to setting the fps so high other than decreased performance? My game uses pixel graphics and a small amount of nodes so its real light.


in Engine by (31 points)

1 Answer

+1 vote

This is a common problem with game physics called "tunnelling". At very high speed this can even cause projectiles to pass through targets. This happens especially if your bullets only "check" collision rather than actually simulating the hit. Upping FPS reduces the effect but isn't a definitive solution.

What's usually supposed to fix it is called CCD: Continuous Collision Detection, although it takes a performance hit and I believe it doesnt work well yet in Godot.

A workaround in case of fast moving bullets is to make them using raycasts. So instead of waiting for a collision hit, you perform a raycast in the direction of the bullet, on a distance equal to the amount travelled by the projectile during one frame. So each frame, you'll be checking collisions along a series of connected segments, without gap, so there won't be "tunnelling".
If no hit is detected, move the projectile.
At some point, one raycast will hit the target. When that happens, instead of moving the projectile like before, place it directly on the hit position, and make it explode there.
This will not only make it work even at very fast speeds, but will also allow precise impact visuals.
It may require a few code changes.

Another way is to give the projectile an elongated collision shape, trailing behind it to be sure that you won't pass through the target, but you'd need to make your projectile a rigidbody or a kinematic with move_and_collide so that it simulates the hit (rather than just checking if the shape overlaps with another). I never tried this approach in Godot though.

by (29,510 points)
edited by
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 Frequently asked questions and 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 [email protected] with your username.