# PhysX Capsule Character Controller floating above ground

I am using PhysX Version 3.0.2 in the simulation package I'm working on, and I've encountered some bizarre behavior with the capsule character controller.

When I set the controller's height and radius to the appropriate values (r = 0.25, h = 1.86)it behaves correctly (moving along the ground, colliding with other objects, and so on) except that the capsule itself is floating above the ground. The actor will then bump his head when trying to get through a door, since the capsule is the correct height but also floating above the ground.

This image should illustrate what I'm going on about:

One can clearly see that the rest of the scene has their collision bodies wrapped correctly, it's just the capsule that's going wrong!

The stop-gap I've implemented is creating a smaller capsule and giving it an offset, but I need to implement ray-picking for the controller next so the capsule has to surround the character model properly.

Here's my character creation code (with height = 1.86f and radius = 0.25f):

NxController* D3DPhysXManager::CreateCharacterController( std::string l_stdsControllerName, float l_fHeight, float l_fRadius, D3DXVECTOR3 l_v3Position )
{
NxCapsuleControllerDesc l_CapsuleControllerDescription;

l_CapsuleControllerDescription.height = l_fHeight;
l_CapsuleControllerDescription.position.set( l_v3Position.x, l_v3Position.y, l_v3Position.z );

l_CapsuleControllerDescription.callback = &this->m_ControllerHitReport;

NxController* l_pController = this->m_pControllerManager->createController( this->m_pScene, l_CapsuleControllerDescription );
this->m_pControllerMap.insert( l_ControllerValuePair( l_stdsControllerName, l_pController ) );
return l_pController;
}


Any help at all would be appreciated, I just can't figure this one out!

P.S. I've found a couple of (rather old) threads describing the same issue, but it seems they couldn't find a solution either. Here are the links:

• What coordinate system is the l_v3Position in? Where are you getting that value from? Where is the origin in the character model in the source artwork? The answer to one of these questions will probably solve your problem. – Tom Whittock Jan 27 '12 at 10:45
• @TomWhittock l_v3Position is in world coordinates and is (0, 0.93, 0). The origin of the character model is the pelvis, but he's being rendered with a negative offset so that his feet touch the ground. My problem is that the capsule is not touching the ground. If everything was working correctly I'd expect the model to be sunk up to his knees in the floor! – Jannie Jan 27 '12 at 11:44
• I don't know PhysX, but: Is it possible that the capsule is actually touching the ground, but the ground's collision volume is above where the ground is being rendered? That would account for the described effects. What are the results if your character stands on one of the "correctly wrapped" bodies? – Kevin Reid Feb 1 '12 at 14:41
• The capsule behaves exactly the same standing on any collision objects in the scene. I'll edit in a screenshot of some correct stacking behavior next to the capsule, for comparison. – Jannie Feb 2 '12 at 5:49

OK, well I figured out this "magic" number ... the capsule will always be [Radius + (Height/2) + contactOffset ] off the ground. Hope this helps someone.

contactOffset is 0.1 by default and if you change it to 0.01 it should be really close to the ground

I had the same problem, Im using Unity 4,

Go to the character controller and change the skin width option to : 0.0001

I don't particularrly know what this does but I changed this option to that and it works, my character can detect the ground correctly on all objects with any type of collider.

Hope this helps :)

Skin width =Two colliders can penetrate each other as deep as their Skin Width. Larger Skin Widths reduce jitter. Low Skin Width can cause the character to get stuck. A good setting is to make this value 10% of the Radius.