Presentation is loading. Please wait.

Presentation is loading. Please wait.

Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract.

Similar presentations


Presentation on theme: "Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract."— Presentation transcript:

1 Physical representation of a game character

2 Basics 05_02_Bullet_CharacterControl_Base.zip Extract Run: CharacterControl.sln Set include and library paths (if not correct) Set working directory (if not $(SolutionDir)/bin) Compile Run

3

4 Exercise Give the character a physical representation Use a capsule shape as a bounding object Make the capsule dynamic Disable rotation Add forces to move it in the scene The 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)

5 PlayerCharacter.h #include "btBulletDynamicsCommon.h" class PlayerCharacter { public: PlayerCharacter(Ogre::SceneManager* sm, btDiscreteDynamicsWorld* phyW); protected: btRigidBody* mPhysicsController;

6 PlayerCharacter.cpp PlayerCharacter::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); }

7 PlayerCharacter.cpp void 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)); }

8 PlayerCharacter.cpp void 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; else action = PA_NONE; pose = PP_RUN; }

9 OgreCharacter.cpp playerCharacter = new PlayerCharacter(sceneManager, physxHandler->getScene());

10 Test

11 More physics Constraints/joints Ray casting (bullets, terrain, vehicle) Complex geometries Convex Concave Height field Collision filtering Soft bodies Particles, fluids

12


Download ppt "Physical representation of a game character. Basics 05_02_Bullet_CharacterControl_Base.zip Extract."

Similar presentations


Ads by Google