Trouble with kinematic character and terrain shape

Post Reply
Anders333
Posts: 3
Joined: Sat Feb 28, 2015 4:20 pm

Trouble with kinematic character and terrain shape

Post by Anders333 »

Hi all.
I implements terrain shape with that code:

Code: Select all

btHeightfieldTerrainShape* groundShape = new btHeightfieldTerrainShape(size, size, data, heightScale, minHeight, maxHeight, upAxis, PHY_FLOAT, true);
	collisionShapes.push_back(groundShape); 
	
	btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(5, 0, 5)));

	btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0));
	btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI); 
	//groundRigidBody->setCollisionFlags(groundRigidBody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
	groundRigidBody->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
	groundRigidBody->setActivationState(DISABLE_DEACTIVATION);
	dynamicsWorld->addRigidBody(groundRigidBody);
where data is float array with size = 11.

Then, i create character, and calling to physics manager for creating kinematic controller:

Code: Select all

btTransform startTransform;
	startTransform.setIdentity();
	startTransform.setOrigin(btVector3(1, 50, 1));

	btPairCachingGhostObject* m_ghostObject = new btPairCachingGhostObject();
	m_ghostObject->setWorldTransform(startTransform);
	btScalar characterHeight = 1.75;
	btScalar characterWidth = 1.75;
	btConvexShape* capsule = new btCapsuleShape(characterWidth, characterHeight);
	m_ghostObject->setCollisionShape(capsule);
	m_ghostObject->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);

	btScalar stepHeight = btScalar(0.35);
	btKinematicCharacterController* m_character = new btKinematicCharacterController(m_ghostObject, capsule, stepHeight);

	dynamicsWorld->addCollisionObject(m_ghostObject, btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter);
	dynamicsWorld->addAction(m_character);
and my FPS falling down to 1-2 from 90.

I've been reading a huge amount of the information and a lot of posts in the gamedev forums, but i still didn't find any solution of this problem.
I will appreciate if anyone would help me to solve it.
Anders333
Posts: 3
Joined: Sat Feb 28, 2015 4:20 pm

Re: Trouble with kinematic character and terrain shape

Post by Anders333 »

I'm trying to draw a debug mesh of my terrain, and get this:
Image
And the debug mesh is different every time I run.
ratatouille
Posts: 21
Joined: Fri Oct 24, 2014 10:48 am

Re: Trouble with kinematic character and terrain shape

Post by ratatouille »

If width = height = 11, shouldn't your data array contain 11x11 = 121 elements instead of 11?
Anders333
Posts: 3
Joined: Sat Feb 28, 2015 4:20 pm

Re: Trouble with kinematic character and terrain shape

Post by Anders333 »

I chaтged size to 51.
Post Reply