Character's (human) Collision and movement

clakinette

20-04-2009 17:43:48

Hi,

I'm actually coding a game with a third person view and I have choosen NxOgre 1.0 for the collisions.
I have got a problem with my character (human). I don't find examples for the moves and the collisions
of a human character. With an Actor or a classic Body the character fall instead of standing up. I have tried
to use a capsule (1,1) for the character's shape, but he is falling again. And I don't understand how to use the
the character class.

Scene creation :

// World
PhysXParams physXParams;
physXParams.mTimeController = PhysXParams::TC_OGRE;
physXParams.mUseLog = true;
m_pNxWorld = new NxOgre::World( physXParams );

// Scene
SceneParams sceneParams;
sceneParams.mRenderer = SceneParams::RN_OGRE;
sceneParams.mGravity.set( 0, -9.8, 0 );
sceneParams.mFloor = true;
m_pNxScene = m_pNxWorld->createScene( "NxOgreScene", sceneMgr, sceneParams );

// Map
NodeRenderableParams nrp;
nrp.setToDefault();
nrp.mIdentifierUsage = NxOgre::NodeRenderableParams::IU_Use;
nrp.mIdentifier = m_pSceneNode->getName();
NxOgre::Resources::ResourceSystem::getSingleton()->addMeshAs( MapNxs, mapName );
m_Body = nxScene->createBody( meshName + "_body", new NxOgre::TriangleMesh( mapName ), m_pSceneNode->getPosition(), nrp, "static:yes" );


Character's creation and movement :
m_pEntity = m_pSceneMgr->createEntity( entityName, meshName );
m_pSceneNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode( nodeName );
m_pSceneNode ->attachObject( m_pEntity );
m_pSceneNode ->setVisible( show );

NodeRenderableParams nrp;
nrp.setToDefault();
nrp.mIdentifierUsage = NxOgre::NodeRenderableParams::IU_Use;
nrp.mIdentifier = m_pSceneNode->getName();

ActorParams actorParams;
actorParams.setToDefault();
actorParams.mMass = 80;
actorParams.mBodyFlags |= NX_BF_FROZEN_ROT_X;
actorParams.mBodyFlags |= NX_BF_FROZEN_ROT_Z;
actorParams.mLinearVelocity.set( 0, 0, 0 );
actorParams.mMassSpaceInertia.set( 1, 0, 1 );
actorParams.mLinearVelocity.set( 1, 0, 1 );
actorParams.mAngularVelocity.set( 1, 0, 1 );

//m_Body = nxScene->createBody( meshName + "_body", new NxOgre::Capsule( 1, 1 ), m_pSceneNode->getPosition(), nrp, actorParams );

NxOgre::Resources::ResourceSystem::getSingleton()->addMeshAs( ressourceNxs, meshName );
m_Body = nxScene->createBody( meshName + "_body", new NxOgre::Convex( meshName ), m_pSceneNode->getPosition(), nrp, actorParams );

m_Body->setGlobalOrientation( m_pSceneNode->getOrientation() );


Character's movement :

if( IsKeyUp() )
{
Ogre::Vector3 direction = Ogre::Vector3( 1, 0.0, 0.0 );
Ogre::Vector3 moveVector = m_pSceneNode->getOrientation() * direction;
m_pSceneNode->translate(moveVector);
m_Body->setGlobalPosition( m_pSceneNode->getPosition() );
}
if( IsKeyDown() )
{
Ogre::Vector3 direction = Ogre::Vector3( -1, 0.0, 0.0 );
Ogre::Vector3 moveVector = m_pSceneNode->getOrientation() * direction;
m_pSceneNode->translate( moveVector );
m_Body->setGlobalPosition( m_pSceneNode->getPosition() );
}
if( IsKeyRight() )
{
m_pSceneNode->roll( Ogre::Degree(0.2) );
m_Body->setGlobalOrientation( m_pSceneNode->getOrientation() );
}
if( IsKeyLeft() )
{
m_pSceneNode->roll( Ogre::Degree(-0.2) );
m_Body->setGlobalOrientation( m_pSceneNode->getOrientation() );
}


With this code the character is standing up, but the physic doesn't work normally and I have a lot of collision
bugs, I think I have done the wrong choice and maybe there is a more easely method for the collisions and the
movement of my character.

P.S : Sorry for my English... :?

nargil

20-04-2009 19:25:02

Thats a lame way to implement character ;) Use either the 1.5.x character or pure physx NxCharacter (yes, within your NxOgre 1.x.x code)

clakinette

20-04-2009 19:58:46

Oh thanks for your help, but i don't find the NxOgre 1.5.x version, where can I find it ?
Using pure physx maybe problematic, no?
If you have a tutorial or example of the implementation of a character, I need it :D !

nargil

20-04-2009 22:02:20

#include <NxCharacter.h>
#include <ControllerManager.h>
#include <CapsuleController.h>

class Character : public NxUserControllerHitReport
...

Character::Character(...)
{
NxControllerManager* mManager = NxCreateControllerManager(GameEngine::getSingletonPtr()->getWorld()->getPhysXDriver()->getUserAllocator());
NxCapsuleControllerDesc desc;
desc.skinWidth = mSkinWidth = 0.1;
desc.climbingMode = CLIMB_CONSTRAINED;
desc.interactionFlag = NXIF_INTERACTION_USE_FILTER;
desc.radius = sqrt(size.x*size.z) * 0.5 - desc.skinWidth;
desc.height = (size.y - desc.radius - desc.skinWidth) / 1.5;
desc.position = NxExtendedVec3(position.x,position.y,position.z);
desc.slopeLimit = 0.707; // .707 = 45*, 0.86 = 30*;
desc.stepOffset = 0.3;
desc.userData = (void*) this;
desc.callback = this;
mController = mManager->createController(GameEngine::getSingletonPtr()->getScene()->getNxScene(), desc);
mCollidable = false;
mController->setCollision(mCollidable);



In a frameListener onFrameStarted you simply move your entity to the mController->getPosition() coordinates.