Physics character controller
Download
1 / 12

Physics Character Controller - PowerPoint PPT Presentation


  • 95 Views
  • Uploaded on

Physics Character Controller. Physical representation of a game character. Basics. http://cg.iit.bme.hu/gamedev/KIC/05_PhysicsEngine/ 05_02_Bullet_CharacterControl _ Base . zip Extract Run : CharacterControl . sln Set i nclude and library paths (if not correct)

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Physics Character Controller' - satya


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Physics character controller

PhysicsCharacter Controller

Physical representation of a game character


Basics
Basics

  • http://cg.iit.bme.hu/gamedev/KIC/05_PhysicsEngine/

  • 05_02_Bullet_CharacterControl_Base.zip

  • Extract

  • Run: CharacterControl.sln

  • Set includeandlibrarypaths (if not correct)

  • Set workingdirectory(if not $(SolutionDir)/bin)

  • Compile

  • Run



Exercise
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)


Playercharacter h
PlayerCharacter.h

#include "btBulletDynamicsCommon.h"

classPlayerCharacter

{

public:

PlayerCharacter(Ogre::SceneManager* sm,btDiscreteDynamicsWorld* phyW);

protected:

btRigidBody* mPhysicsController;


Playercharacter cpp
PlayerCharacter.cpp

PlayerCharacter::PlayerCharacter(Ogre::SceneManager* sm, btDiscreteDynamicsWorld* phyW)

{

btCollisionShape* physicsShape = newbtCapsuleShape(2.0,5.0);

btDefaultMotionState* physicsMotionState =

newbtDefaultMotionState(btTransform(btQuaternion(0,0,0,1),

btVector3(0,5,0)));

btScalarmass = 1;

btVector3 inertia(0,0,0);

physicsShape->calculateLocalInertia(mass,inertia);

btRigidBody::btRigidBodyConstructionInforigidBodyCI(mass,

physicsMotionState,

physicsShape,

inertia);

mPhysicsController = newbtRigidBody(rigidBodyCI);

mPhysicsController->setAngularFactor(0); //disable rotation

//mPhysicsController->setDamping(0.3,0);

phyW->addRigidBody(mPhysicsController);

}


Playercharacter cpp1
PlayerCharacter.cpp

void PlayerCharacter::update(float t, float dt)

{

btTransformworldTrans;

mPhysicsController->getMotionState()->getWorldTransform(worldTrans);

//we don’t need rotation as it is fixed

//btQuaternionrot = 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));

}


Playercharacter cpp2
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;

}


Ogrecharacter cpp
OgreCharacter.cpp

playerCharacter = new PlayerCharacter(sceneManager, physxHandler->getScene());



More physics
More physics

  • Constraints/joints

  • Ray casting (bullets, terrain, vehicle)

  • Complex geometries

    • Convex

    • Concave

    • Height field

  • Collision filtering

  • Soft bodies

  • Particles, fluids



ad