How do you control a player character in Bullet Physics?
I am not sure how you are supposed to control a player character in
Bullet. The methods that I read were to use the provided
btKinematicCharacterController. I also saw methods that use
btDynamicCharacterController from the demos. However, in the manual it is
stated that kinematic controller has several outstanding issues. Is this
still the preferred path? If so, are there any tutorials or documentations
for this? All I found are snippets of code from the demo, and the usage of
controllers with Ogre, which I do not use.
If this is not the path that should be tread, then someone point me to the
correct solution. I am new to bullet and would like a straightforward,
easy solution. What I currently have is hacked together bits of a
btKinematicCharacterController.
This is the code I used to set up the controller:
playerShape = new btCapsuleShape(0.25, 1);
ghostObject= new btPairCachingGhostObject();
ghostObject->setWorldTransform(btTransform(btQuaternion(0,0,0,1),btVector3(0,20,0)));
physics.getWorld()->getPairCache()->setInternalGhostPairCallback(new
btGhostPairCallback());
ghostObject->setCollisionShape(playerShape);
ghostObject->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);
controller = new btKinematicCharacterController(ghostObject,playerShape,0.5);
physics.getWorld()->addCollisionObject(ghostObject,btBroadphaseProxy::CharacterFilter,
btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
physics.getWorld()->addAction(controller);
This is the code I use to access the controller's position:
trans = controller->getGhostObject()->getWorldTransform();
camPosition.z = trans.getOrigin().z();
camPosition.y = trans.getOrigin().y()+0.5;
camPosition.x = trans.getOrigin().x();
The way I control it is through setWalkDirection() and jump() (if
canJump() is true).
No comments:
Post a Comment