Problem between Terrain and Kinematic Character

nsdavidlj
Posts: 10
Joined: Mon Oct 26, 2009 3:40 pm

Problem between Terrain and Kinematic Character

Post by nsdavidlj »

I have create kinematiccharacter in my application like CharacterDemo,but replaced scene shape with TerrainShape.
But my character will pass through the terrain without collision.
And I also tested rigid body with capsule,sphere,box,but they were working well with terrain.
Where is my problem?

init terrain:

Code: Select all

int			nUpAxis = 2;

		m_pShape = new btHeightfieldTerrainShape(m_szGrid
																,m_szGrid
																,&m_vHeightField[0]
																,1.0f
																,fMinHeight
																,fMaxHeight
																,nUpAxis
																,PHY_FLOAT
																,bFlipQuadEdges);

		btAssert( (!m_pShape || m_pShape->getShapeType() != INVALID_SHAPE_PROXYTYPE) );

		btVector3	localInertia;
		m_pShape->calculateLocalInertia(0.0f,localInertia);

		btTransform	myTransform;
		myTransform.setIdentity();

		m_pRigidBody = new btRigidBody(0.0f,new btDefaultMotionState(myTransform),m_pShape,localInertia);
init KinematicCharacter:

Code: Select all

m_pShape = new btCapsuleShapeZ(0.5f,0.5f);

		m_vOrient = btVector3(0.0f,0.0f,0.5f);

		btScalar	mass(1.0f);

		//rigidbody is dynamic if and only if mass is non zero, otherwise static
		bool isDynamic = (mass != 0.f);

		btVector3 localInertia(0,0,0);
		m_pShape->calculateLocalInertia(mass,localInertia);

btTransform startTransform;
		startTransform.setIdentity();

		CPXRigidBody *pBody = dynamic_cast<CPXRigidBody*>(p);

		m_pGhostObject = new btPairCachingGhostObject();
		startTransform = pBody->GetBody()->getWorldTransform();

		m_pGhostObject->setWorldTransform(startTransform);
		//btScalar characterHeight=0.25;
		//btScalar characterWidth =0.25;
		m_pGhostObject->setCollisionShape (m_pShape);

		m_pCharacter = new btKinematicCharacterController (m_pGhostObject
															,m_pShape)
															,0.2
															,2);
		m_pCharacter->setWalkDirection(btVector3(0.0f,0.0f,0.0f));

		m_pGhostObject->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);

pScene->m_pOverlappingPairCache->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());

		m_pDynamicsWorld->addCollisionObject(m_pGhostObject
															,btBroadphaseProxy::CharacterFilter
															,btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
		m_pDynamicsWorld->addCharacter(m_pCharacter);
Why do them (kinematic character and terrain) no collision? Help!
Last edited by nsdavidlj on Thu Nov 05, 2009 4:29 pm, edited 2 times in total.
nsdavidlj
Posts: 10
Joined: Mon Oct 26, 2009 3:40 pm

Re: Problem between Terrain and Kinematic Character

Post by nsdavidlj »

I tried set character->setUseGhostSweepTest(false);

character can be hit and stop on the terrain surface.

why?

Code: Select all

if (m_useGhostObjectSweepTest)
{
	m_ghostObject->convexSweepTest (m_convexShape, start, end, callback, collisionWorld->getDispatchInfo().m_allowedCcdPenetration);
}
else
{
            collisionWorld->convexSweepTest (m_convexShape, start, end, callback, collisionWorld->getDispatchInfo().m_allowedCcdPenetration);
	}
nsdavidlj
Posts: 10
Joined: Mon Oct 26, 2009 3:40 pm

Re: Problem between Terrain and Kinematic Character

Post by nsdavidlj »

I found reason,it was using btDbvtBroadphase has btBroadphaseInterface

Code: Select all

btDiscreteDynamicsWorld(m_pDispatcher,new btDbvtBroadphase(),m_pConstraintSolver,m_pCollisionConfiguration)
So I replace it with

Code: Select all

new btAxisSweep3
,btKinematicCharacter will be stand up on the terrain.
What's the different with btAxisSweep3 and btDbvtBroadphase?