Hello all,
I'm using BULLET in a framework I'm developing for future projects, and decided to have a go at simulating projectiles for first person shooters. I find using Bullet ideal, since you're able to simulate damping and gravity, for air friction and proper drop figures.
For now- just so I'd have something working, I have my projectile body, and when it is "fired", I'm simply setting the direction and applying local force to it to drive it forward- a force of around 20,000 on an object with a mass of 10. That works well for my intended purpose. It flies forward and looks like a projectile, and will eventually drop and hit the terrain where it will be destroyed.
Problem is, it doesn't always detect the contact, and will fly right through other bodies. I have a few Convex hulls scattered around to plink at, and it works on and off, but overall is pretty unreliable. I'm curious if there's a way to improve the contact responses, or if there's another way to properly simulate projectiles in Bullet.
Here is a video of a small test, just as a reference. Sorry for the slow physics times, for some reason FRAPS screwed up the math - Any pointers on how to keep a consistent sim speed?
http://www.youtube.com/watch?v=_wt-8xiyACA
Improving contact response on fast moving bodies?
-
- Posts: 4
- Joined: Fri Oct 05, 2012 7:56 am
-
- Posts: 6
- Joined: Wed Sep 26, 2012 10:46 pm
Re: Improving contact response on fast moving bodies?
Hi m8 I great little demo here my view on programming remember most games stuff is all fake'ish
first of make shore you try keep thing to scale like 1 to 1 large graphics objects give the impression
things are moving slower than they are you mite find that if you make the map and gun smaller thing look like there moving faster I.E you can slow moving objects slower.
second of all I would fake it again use a muzzle flash from gun and use a RAY not a sphere
that way the bullet is instant and it's a definite connection with an object this is what i have done in the past
when crating shooting games hope this helps
ross
first of make shore you try keep thing to scale like 1 to 1 large graphics objects give the impression
things are moving slower than they are you mite find that if you make the map and gun smaller thing look like there moving faster I.E you can slow moving objects slower.
second of all I would fake it again use a muzzle flash from gun and use a RAY not a sphere
that way the bullet is instant and it's a definite connection with an object this is what i have done in the past
when crating shooting games hope this helps
ross
-
- Posts: 4
- Joined: Fri Oct 05, 2012 7:56 am
Re: Improving contact response on fast moving bodies?
Hi Ross,
I thought about using a ray, but call me lazy - I'd miss the simulated air friction and gravity on the object (but i guess those things don't matter if the object won't collide!) - I could work out my own math for using rays, but would like to find a solution. Thinking about it, I could sample the projectiles current / previous coordinates, and check using a ray between them. If it passes through what you're shooting at, the ray should be able to detect it.
What do you think?
I thought about using a ray, but call me lazy - I'd miss the simulated air friction and gravity on the object (but i guess those things don't matter if the object won't collide!) - I could work out my own math for using rays, but would like to find a solution. Thinking about it, I could sample the projectiles current / previous coordinates, and check using a ray between them. If it passes through what you're shooting at, the ray should be able to detect it.
What do you think?
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Improving contact response on fast moving bodies?
The latest Bullet 2.81 can add predictive contacts for fast moving objects. Check out the Bullet/Demos/CcdPhysicsDemo.
Make sure this radius is smaller than the collision shape, so that it is embedded inside the shape. For example, for a btBoxShape with half extents of (1,1,1),
a good radius to choose is 0.9. The CCD is enabled once the motion of the body in one simulation frame exceeds the motion threshold.
Thanks,
Erwin
Make sure this radius is smaller than the collision shape, so that it is embedded inside the shape. For example, for a btBoxShape with half extents of (1,1,1),
a good radius to choose is 0.9. The CCD is enabled once the motion of the body in one simulation frame exceeds the motion threshold.
Code: Select all
body->setCcdMotionThreshold(velocityThreshold);
body->setCcdSweptSphereRadius(radius);
Erwin
-
- Posts: 4
- Joined: Fri Oct 05, 2012 7:56 am
Re: Improving contact response on fast moving bodies?
Hi Erwin,
This worked fantastically! I've even benchmarked it to see if there's any way to break it, and doesn't seem so. I was using the above suggested with raycasts, but which is more costly - doing picks or testing for collisions?
This worked fantastically! I've even benchmarked it to see if there's any way to break it, and doesn't seem so. I was using the above suggested with raycasts, but which is more costly - doing picks or testing for collisions?