Download - Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract
![Page 1: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/1.jpg)
Physics Character Controller
Physical representation of a game character
![Page 2: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/2.jpg)
Basicshttp://cg.iit.bme.hu/gamedev/KIC/
05_PhysicsEngine/05_02_Bullet_CharacterControl_Base.zipExtractRun: CharacterControl.slnSet include and library paths (if not correct)Set working directory (if not
$(SolutionDir)/bin)CompileRun
![Page 3: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/3.jpg)
Run
![Page 4: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/4.jpg)
ExerciseGive the character a physical representationUse a capsule shape as a bounding objectMake the capsule dynamicDisable rotationAdd forces to move it in the sceneThe physical representation of the scene is
already loaded (static boxes)(examine the source code!!)
Play with the parameters until the movement feels natural
(Next slides show one solution)
![Page 5: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/5.jpg)
PlayerCharacter.h#include "btBulletDynamicsCommon.h"
class PlayerCharacter{public: PlayerCharacter(Ogre::SceneManager* sm, btDiscreteDynamicsWorld*
phyW);
protected: btRigidBody* mPhysicsController;
![Page 6: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/6.jpg)
PlayerCharacter.cppPlayerCharacter::PlayerCharacter(Ogre::SceneManager* sm, btDiscreteDynamicsWorld* phyW){
… btCollisionShape* physicsShape = new btCapsuleShape(2.0,5.0);
btDefaultMotionState* physicsMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,5,0))); btScalar mass = 1; btVector3 inertia(0,0,0); physicsShape->calculateLocalInertia(mass,inertia);
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, physicsMotionState, physicsShape, inertia); mPhysicsController = new btRigidBody(rigidBodyCI);
mPhysicsController->setAngularFactor(0); //disable rotation//mPhysicsController->setDamping(0.3,0);
phyW->addRigidBody(mPhysicsController);}
![Page 7: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/7.jpg)
PlayerCharacter.cppvoid PlayerCharacter::update(float t, float dt){
… btTransform worldTrans;
mPhysicsController->getMotionState()->getWorldTransform(worldTrans);
//we don’t need rotation as it is fixed//btQuaternion rot = worldTrans.getRotation();
//node->setOrientation(rot.w(), rot.x(), rot.y(), rot.z());
node->setPosition(worldTrans.getOrigin().x(), worldTrans.getOrigin().y()-5, worldTrans.getOrigin().z());
mPhysicsController->setLinearVelocity(btVector3(0,0,0));
}
![Page 8: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/8.jpg)
PlayerCharacter.cppvoid PlayerCharacter::move(float amount){
if(inAction())return;
Ogre::Vector3 m = amount * getDirection() * 150;Ogre::LogManager::getSingleton().logMessage("Applying force: " + Ogre::StringConverter::toString(m));mPhysicsController->activate(true);mPhysicsController->applyImpulse(btVector3(m.x,m.y,m.z), btVector3(0,-0.5,0));
if(hasWeapon)action = PA_WEAPON_HOLD;
elseaction = PA_NONE;
pose = PP_RUN;}
![Page 9: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/9.jpg)
OgreCharacter.cppplayerCharacter = new
PlayerCharacter(sceneManager, physxHandler->getScene());
![Page 10: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/10.jpg)
Test
![Page 11: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/11.jpg)
More physicsConstraints/jointsRay casting (bullets, terrain, vehicle)Complex geometries
ConvexConcaveHeight field
Collision filteringSoft bodiesParticles, fluids
![Page 12: Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract](https://reader037.vdocument.in/reader037/viewer/2022110116/551a6f1e5503463e778b5f41/html5/thumbnails/12.jpg)
The End