Hello. I'm fairly new to bullet and new to graphics programming in general. I was wondering if it's possible to use a rigid body box as the collision detection for my first person camera by manually moving it and then querying Bullet for any collisions after? The way I'm doing it right now is by doing a sweep test of the camera coordinates before and after moving with just a collision shape, not a body. It's sort of working but the problem is that as soon as it detects any form of collision while moving you stop completely, I mean it's really sticky once you collide with something instead of letting you slide around the collision surface or so to speak. Here's what my current code looks like(BeforePos is a vector of the camera position before movement, CurrentPos is a vector of the position after movement):
Code: Select all
btVector3 CameraBeforePos(BeforePos.X, BeforePos.Y, BeforePos.Z);
btVector3 CameraAfterPos(CurrentPos.X, CurrentPos.Y, CurrentPos.Z);
btTransform CameraBefore, CameraAfter;
CameraBefore.setIdentity();
CameraBefore.setOrigin(CameraBeforePos);
CameraAfter.setIdentity();
CameraAfter.setOrigin(CameraAfterPos);
btCollisionWorld::ClosestConvexResultCallback CollisionCallback(CameraBeforePos, CameraAfter.getOrigin());
CollisionCallback.m_collisionFilterMask = btBroadphaseProxy::StaticFilter;
XPhysics->DynamicsWorld->convexSweepTest(CamCollisionShape, CameraBefore, CameraAfter, CollisionCallback);
if(CollisionCallback.hasHit())
{
const btScalar MinimumFraction = CollisionCallback.m_closestHitFraction;
CameraAfterPos.setInterpolate3(CameraBefore.getOrigin(), CameraAfter.getOrigin(), MinimumFraction);
CurrentPos.X = CameraAfterPos.x();
CurrentPos.Y = CameraAfterPos.y();
CurrentPos.Z = CameraAfterPos.z();
}
Is there any smarter way to let the physics engine handle the collision with a manually moved rigid body which allows you to walk into a wall and instead of getting stuck to it you traverse along it? Or can I easily mend this code to do the same thing? I appreciate any answers