I am using Bullet, and am attempting to make a collision algorithm that generates contact points off of a cube-based terrain along with the appropriate collision response. I also plan to extend this to include non-box shapes too, however that is not vital at the moment. I've found that using a triangle mesh is too much of a RAM hog for large maps.
I have tried the procedure outlined by Byte56 here, 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_shapeTypeto 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
What I've done:
- I've created a terrainShape
, the only difference being thatm_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
btRigidBodyclass 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
cois not air.
I've extended the
btCollisionAlgorithmclass, in a way similar to
processCollisiondoing the following:
- Check the colliding objects passed as arguments, and determine which is the terrain, and which is the entity.
- Clear the manifolds any child algorithms.
- 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.
- Iterate over all child algorithms, calling
- Iterate over all child algorithms, removing any now outside of the AABB of the colliding entity. (calling
processCollision is called whenever the player's AABB intersects with non-air voxels.
What doesn't: the collision response 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 with respect to