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 :
Character's creation and movement :
Character's movement :
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...
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...