Is it possible to manually move rigidbodies and do collision

Post Reply
Roflcopter
Posts: 3
Joined: Wed May 06, 2015 12:29 am

Is it possible to manually move rigidbodies and do collision

Post by Roflcopter »

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 :)
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Is it possible to manually move rigidbodies and do colli

Post by benelot »

You can easily move rigidbodies manually by moving them via their world transforms and then let the physics dynamics world do the rest for you. If your object hits the wall, it will stop moving, so you can place your camera relative to the object, so that it stops as well. Did you find a solution?
Post Reply