[ Working With Physx Controllers ]

Working with a simple Physx Character Controller, You can use basic shapes ( Box and Capsule ) for character collision detection.
here is a code for Ogre3D and Nvidia Physx.

void NxScene3DObjectCamera::
CreateCharacterController( NxScene * scene, NxVec3 pos, float radius, float height)
{
Log("Creating a Camera Controller...");
// Defines the maximum height of an obstacle which the character can climb.
float stepOffset = 0.5f;
float SkinWidth = 0.01f;//0.01f; // important for elevator and kinematic object
CurrentNxScene = scene;</p>
<p style="text-align: left;">NxCapsuleControllerDesc desc;
desc.position = NxExtendedVec3( pos.x, pos.y, pos.z );
//Ogre::Vector3 size(0.5,1.80,0.5);
desc.radius = radius;// you could use sqrt(size.x*size.z) * 0.5 - desc.skinWidth;
desc.height = height;// you could use (size.y - desc.radius - desc.skinWidth) / 1.5;
// The maximum slope which the character can walk up.
desc.slopeLimit = cosf( NxMath::degToRad( 60.0f ) );
desc.stepOffset = stepOffset; // see CLIMB_CONSTRAINED
desc.skinWidth = SkinWidth;
desc.upDirection = NX_Y;
desc.climbingMode = CLIMB_EASY;
mCallback = new NxScene3DObjectCameraCallback( this );
desc.callback = mCallback;
mController = NxScene3DManager::getSingleton().GetPhysicsControllerManager()-&gt;createController( scene, desc );</p>
// Access the base Shape
NxCapsuleController * capsuleCtrl = ((NxCapsuleController*) mController);
// Set the Capsule Height
capsuleCtrl-&gt;setHeight( WalkStandUpHeight );
// Set the way the controller interacts with other controllers.
mController-&gt;setInteraction( NXIF_INTERACTION_USE_FILTER );
// Enable collisions.
mController-&gt;setCollision( true );
// Set Controller Group
capsuleCtrl-&gt;getActor()-&gt;setGroup( GROUP_CHARACTER );

static int Increment = 0; Increment++;
Ogre::String Tmp = Ogre::String( "Character_"+ Ogre::StringConverter::toString(  Increment )  );
capsuleCtrl-&gt;getActor()-&gt;setName( (const char *)Tmp.c_str() );
capsuleCtrl-&gt;getActor()-&gt;setContactReportFlags(  NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_ON_TOUCH | NX_NOTIFY_ON_END_TOUCH );
capsuleCtrl-&gt;getActor()-&gt;setMass(100);
//capsuleCtrl-&gt;getActor()-&gt;setContactReportThreshold( 100 );
<p style="text-align: left;">SetCollisionDetection( false );
CameraTranslate( TranslateMode::TranslateNone );
mActive = true;
Log("Creating a Camera Controller : Done.");
}

Comments are closed.