Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am using Bullet, and am attempting to make a collision algorithm that generates contact points off of a voxel (cube) based terrain, and creates the appropriate collision response. I also plan to extend this to include non-box shapes too, however that is not vital atm. I've found that using a trimesh is too much of a RAM hog for large maps.

I have tried the procedure outlined by Byte56 here, How do I implement a Bullet Physics CollisionObject that represents my cube like terrain? , however, I have a number of questions regarding implementing this with Bullet.

  • How do you generate a collision shape for the world? Do you use a custom shape? What do you set m_shapeType to be on it?
  • Or do you still use a box shape the size of the world?
  • How do you ensure that contact points are freed?
  • How exactly do you modify processCollision?

What I've done:

  • I've created a "terrainShape" that extends btBoxShape, the only difference being that m_shapeType = CUSTOM_CONVEX_SHAPE_TYPE, in order for me to be able to register a new collision algorithm with the dispatcher for objects with only this shape.
  • I've extended the btRigidBody class in a way similar to Byte56 in his question (see the link in the 2nd paragraph), however checkCollisionWith(CollisionObject * co) returns true if ANY voxel in the aabb of co is not air.
  • I've extended the btCollisionAlgorithm class, in a way similar to btCompoundCollisionAlgorithm, with processCollision doing the following:

    1. Check the colliding objects passed as arguments, and determine which is the terrain, and which is the entity.
    2. Clear the manifolds any child algorithms.
    3. Call resultOut->setPersistantManifold(resultOut)
    4. Generate new box shapes and transforms in the AABB occupied by the colliding entity, and then call m_dispatcher->findAlgorithm. Store the shape, transform and found algorithm in a Child Algorithm struct for each voxel within the AABB.
    5. Iterate over all child algorithms, calling proccessCollision.
    6. Iterate over all child algorithms, removing any now outside of the AABB of the colliding entity. (calling ~btCollisionAlgorithm() then m_dispatcher->freeCollisionAlgorithm())
    7. Call resultOut->refreshContactPoints().

What works: processCollision is called whenever the player's aabb intersects with non-air voxels.

What doesn't: The collision response is is just plain weird... The player entity starts levitating upwards. If it walks into something, it bounces off violently. Sometimes, it is unable to keep moving on one axis after walking into something. What I suspect is going on is that contact points are not being released after collision response, possibly due to the player entity always being in the world object's aabb. I am curious to see if I am barking up the right tree w.r.t processCollision. Cheers.

share|improve this question
Did you sort this out at all? I'm having a very similar issue. – timoxley Mar 7 at 8:40
A bit late, sorry, I didn't see your question. If you haven't figured this out already, have you tried the debug drawing of your physics bodies? The AABB you're using to detect the collision does not bound the physics body you're using. So by the time you detect the collision, your object is already far inside of it. This explains why your collision reactions are so strange. – Byte56 Mar 30 at 1:59
See my latest answer to my question: gamedev.stackexchange.com/questions/27405/… – Byte56 Mar 31 at 0:35

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.