2

I'm trying to make a basic first person shooter game with Bullet and OpenGL. I'm having the issue of my rigid bodies not colliding at high speed.

My bullets will go straight through any other rigid bodies that I have, such as walls. Reducing velocity to less than 10 does result in collisions, but this is too low for a moving bullet. The bullet also moves insanely fast (I know it's a fast moving bullet, but sometimes I can't even see it, not sure if that's expected).

I'm thinking that it's to do with how I'm stepping the simulation? Reading up on it has left me confused. How can I make it so that my objects will always collide (at least, when going reasonably fast), and if possible, is there a way to slow the simulation down whilst maintaining the correct bullet velocity etc. so that I can actually see the bullet moving and colliding?

  • Is this in Unity? – Glen Pierce Apr 02 '17 at 21:36
  • How are you detecting collisions in the code? – Seth Difley Apr 02 '17 at 21:45
  • Not in Unity, just c++ code using OpenGL and Bullet. And for detecting collisions, I'm simply letting Bullet handle it, I don't have collision flags. I believe Bullet handles collision by default (look at Bullet's falling sphere tutorial), and my bullets do collide with walls, floors etc. when travelling relatively slowly (They'll fall to the floor and rest on the floor rigid body for example) – Jack Phipps Apr 02 '17 at 21:50
  • Your bullet is probably travelling so fast that on each frame, it's either too early to collide with the surface or too late. A solution would be to check if the bullet will collide with a surface before the next time it's position is going to be recalculated. – Glen Pierce Apr 02 '17 at 22:00
  • That sounds like a possible solution. How would I check that with Bullet? Currently I have no test for collisions and my bullet simply moves due to setting it's linear velocity when it's created. – Jack Phipps Apr 02 '17 at 22:05

1 Answers1

2

Here are some approaches to solve:-
It is copied from How can I avoid missing collisions for fast moving objects? - an official FAQ

  • smaller timesteps
  • extruding the object along the motion
  • ray cast to the new position
  • swept collision test (convex cast, linear cast)
  • continuous collision detection, including rotational motion

Please read the link for more detail. It is not a trivial issue.
One important thing to ask before try anything: do you really need high speed object?
It is not free (cost more CPU).

Here is another useful link (less useful though) : https://gamedev.stackexchange.com/questions/11961/how-can-i-enable-ccd-in-bullet-physics

Community
  • 1
  • 1
javaLover
  • 6,347
  • 2
  • 22
  • 67
  • Interesting, plenty of possible solutions, thanks. I'll mark your as accepted for now, and I might post here with my solution. I do need the objects to be high speed though, as they are bullets and due to what I'm trying to implement, ray casting to a position isn't an option. – Jack Phipps Apr 03 '17 at 21:06
  • 3
    Actually, @javaLover, the last point in your suggestions was a quick and simple fix, using continuous collision detection was a good way to go. For anyone else with this issue, try something along these lines: bulletRigidBody->setCcdMotionThreshold(1e-7); bulletRigidBody->setCcdSweptSphereRadius(0.50); – Jack Phipps Apr 03 '17 at 21:15
  • @Jack Phipps Thank a lot for sharing a snippet. It will be really useful for many ones. – javaLover Apr 04 '17 at 01:54
  • Very useful well summarized answer, but the code snipet from @JackPhipps makes it even better. – Avi May 07 '21 at 13:24