I've successfully integrated the Bullet Physics library into my entity/component system. Entities can collide with each other. Now I need to enable them to collide with the terrain, which is finite and cube-like (think InfiniMiner or it's clone Minecraft). I only started using the Bullet Physics library yesterday, so perhaps I'm missing something obvious.
So far I've extended the RigidBody
class to override the checkCollisionWith(CollisionObject co)
function. At the moment it's just a simple check of the origin, not using the other shape. I'll iterate on that later. For now it looks like this:
@Override
public boolean checkCollideWith(CollisionObject co) {
Transform t = new Transform();
co.getWorldTransform(t);
if(COLONY.SolidAtPoint(t.origin.x, t.origin.y,t.origin.z)){
return true;
}
return false;
}
This works great, as far as detecting when collisions happen. However, this doesn't handle the collision response. It seems that the default collision response is to move the colliding objects outside of each others shapes, possibly their AABBs.
At the moment the shape of the terrain is just a box the size of the world. This means the entities that collide with the terrain just shoot away to outside that world size box. So it's clear that I either need to modify the collision response or I need to create a shape that conforms directly to the shape of the terrain. So which option is best and how do I go about implementing it? Perhaps there's an option I'm not thinking of?
It should be noted that the terrain is dynamic and frequently modified by the player.