What I do is create a btCylinderShape for the character and add it to the collision world.
The environment exists as a series of btConvexHullShape's.
To detect collisions I use collisionWorld->contactTest(), passing the cylinder of the character that I want to move in every frame.
This is what I'm doing on the callback to know if I'm colliding and by how much I'm penetrating the object.
Code: Select all
virtual btScalar addSingleResult(btManifoldPoint& cp,
const btCollisionObjectWrapper* colObj0,
int partId0,int index0,
const btCollisionObjectWrapper* colObj1,int partId1,int index1)
{
btVector3 pt; // will be set to point of collision relative to body
if(colObj0->getCollisionObject()==&body) {
pt = cp.m_localPointA;
} else {
//assert(colObj1==&body && "body does not match either collision object");
pt = cp.m_localPointB;
}
ContactInfo ci;
ci.normal = v3(cp.m_normalWorldOnB.x(), cp.m_normalWorldOnB.y(), cp.m_normalWorldOnB.z());
ci.distance = cp.getDistance();
return 0;
}
Problem with this is that the behavior isn't soft enough. It results in me penetrating the walls a tiny amount and springing from them, as the penetration distance returned is never enough. It feels like walls are a cushion. How would I go about making collisions work in an accurate, rigid way?
If I'm not explaining myself correctly please let me know.
Thanks in advance.