Collision and ballistics

fullmetalcoder
Posts: 29
Joined: Mon May 19, 2008 5:01 pm

Collision and ballistics

Post by fullmetalcoder »

Hi,

I am currently working on a game project (roughly a tech demo until now) using Irrlicht as a 3d engine. I choose to use Bullet to handle the collision and ballistics but I'm facing two issues :
* how do I load the environment properly so that other models don't fall through it? I tried loading as a rigid body with a triangle mesh shape (because the only thing I can get from it is a list of triangles...) but it looks like the limitation mentioned in the docs about big objects is making this approach useless... Any hint?
* how do I handle ballistics (which involve small projectiles moving very fast) since the docs states that such situations are likely to be badly handled (something about tunneling if I remember well...)?

regards

fullmetalcoder
User avatar
shotgunnutter
Posts: 17
Joined: Thu Nov 01, 2007 2:13 am

Re: Collision and ballistics

Post by shotgunnutter »

fullmetalcoder wrote: * how do I load the environment properly so that other models don't fall through it? I tried loading as a rigid body with a triangle mesh shape (because the only thing I can get from it is a list of triangles...) but it looks like the limitation mentioned in the docs about big objects is making this approach useless... Any hint?
This is best handled by having several bullet trimeshes, and then scanning through the static geometry (imagine a large mountain for example) and adding each triangle to the closest section. That way, you keep the AABB of each section small, and therefore will reduce the number of dynamic objects inside each section. Something like

Code: Select all

FOR each triangle
      IF a bullet trimesh already exists in that position
           add triangle to that trimesh
      ELSE
           create a new trimesh in that location
           add triangle to that trimesh
      END IF
NEXT
}
* how do I handle ballistics (which involve small projectiles moving very fast) since the docs states that such situations are likely to be badly handled (something about tunneling if I remember well...)?
fullmetalcoder
Very small, fast objects can be simulated with a raycast. On each frame, cast a ray from its last position to its current position, and anything it came into contact with is hit by the bullet. Most games simply do a single raycast from the end of the gun into infinity and whichever object was struck first gets "shot".
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Re: Collision and ballistics

Post by AlexSilverman »

On the topic of static level geometry, it was my understanding that taking advantage of the bvh tree in the btBvhTriangleMeshShape (by putting as many static triangles in one mesh as you could) provided bigger gains than enabling pruning in the way you mention (by creating more AABBs). This also eases creation, as you no longer have to worry where each triangle is, and you can just throw them all in together.

- Alex
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Collision and ballistics

Post by Erwin Coumans »

As AlexSilverman mentions, it is best to add all triangles to one or just a few btBvhTriangleMeshShape static objects. It is better to merge static triangle meshes to reduce the number of static broad phase AABBs.

As shotgunnutter mentions, you can use a ray cast or convex cast, check out btCollisionWorld::convexSweepTest, and clamp the motion for fast moving objects. You can also try out the unfinished btContinuousDynamicsWorld, it prevents tunneling. But this is work-in-progress and is 'done when its done'.

Hope this helps,
Erwin
fullmetalcoder
Posts: 29
Joined: Mon May 19, 2008 5:01 pm

Re: Collision and ballistics

Post by fullmetalcoder »

Thanks for the info about ballistics, I'll look into this when I find time (if you can give me more explanations about ray casting I'd be grateful).

As for the collision with the environment it turns out concave/concave collisions are not handled by default. I suppose I have to use GImpact to achieve that. Unfortunately the doc on that aspect is rather... thin. Any pointers?
User avatar
detox
Posts: 12
Joined: Wed Nov 22, 2006 6:52 pm
Location: Ohio, USA

Re: Collision and ballistics

Post by detox »

rather than doing concave-concave collisions you could check out the convex decomposition demo to see how to create a convex approximation of your dynamic concave shape and do concave-convex collisions between your dynamic object and static collision terrain. It's a little simpler and possibly faster too. If you need real concave shapes you could create it out of multiple convex shapes