Character controller cause crash

Post Reply
peymankop
Posts: 6
Joined: Wed Nov 02, 2016 4:05 pm

Character controller cause crash

Post by peymankop »

hi,i want to implement character controller so i'v downloaded the character controller demo. here is my character controller code:
m_owner = _owner;

Code: Select all

btTransform startTransform;
	if (GetOwner())
	{
		//Set start transform for physics
		startTransform.setIdentity();
		startTransform.setOrigin(btVector3(GetOwner()->GetComponent<Transform>()
			->GetPosition()->GetX(),
			GetOwner()->GetComponent<Transform>()
			->GetPosition()->GetY(),
			GetOwner()->GetComponent<Transform>()
			->GetPosition()->GetZ()));

		btQuaternion quat;
		quat.setEuler(GetOwner()->GetComponent<Transform>()
			->GetRotation()->GetY(),
			GetOwner()->GetComponent<Transform>()
			->GetRotation()->GetX(),
			GetOwner()->GetComponent<Transform>()
			->GetRotation()->GetZ());
		startTransform.setRotation(quat);
	}
	m_ghostObject = new btPairCachingGhostObject();
	m_ghostObject->setWorldTransform(startTransform);
	AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetPhysicManager()
		->GetOverlappingPairCache()
		->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
	btScalar characterHeight = 0.75;
	btScalar characterWidth = 0.75;
	btConvexShape* capsule = new btCapsuleShape(characterWidth, characterHeight);
	m_ghostObject->setCollisionShape(capsule);
	m_ghostObject->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT | btCollisionObject::CF_KINEMATIC_OBJECT);

	btScalar stepHeight = btScalar(0.35);
	m_character = new btKinematicCharacterController(m_ghostObject, capsule, stepHeight);
	AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetPhysicManager()->GetDynamicWorld()->
		addCollisionObject
		(m_ghostObject, btBroadphaseProxy::CharacterFilter,
			btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter);

	AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetPhysicManager()->GetDynamicWorld()->
		addAction(m_character);

	AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetPhysicManager()->GetDynamicWorld()
		->getBroadphase()->getOverlappingPairCache()->
		cleanProxyFromPairs(m_ghostObject->getBroadphaseHandle(), 
			AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetPhysicManager()->GetDynamicWorld()->
			getDispatcher());
	m_character->reset(AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetPhysicManager()->GetDynamicWorld());
	m_ghostObject->setUserPointer(_owner);
and here is my convex shape creation:

Code: Select all

btScalar * points = new btScalar[vec[i]->pointsSize*3];
			btConvexHullShape *tmp = new btConvexHullShape();
			for (unsigned int j = 0;j < vec[i]->pointsSize;j++)
			{
				points[j * 3 + 0] = vec[i]->points[j].x;
				points[j * 3 + 1] = vec[i]->points[j].y;
				points[j * 3 + 2] = vec[i]->points[j].z;
			}
			btTriangleIndexVertexArray * data =
				new btTriangleIndexVertexArray(vec[i]->indicesSize / 3, (int*)vec[i]->indciesInt.data(), 3 * sizeof(int)
					, vec[i]->pointsSize, points, 3 * sizeof(btScalar));
			
			m_meshRigidData[i].collisionShape = new btBvhTriangleMeshShape(data, true, true);
			m_meshRigidData[i].collisionShape->setMargin(0.5f);
problem is every time my character controller hit a convex shape that loaded like above code my program crashes at line "Step Simulation" is anything wrong with my loading?
also if i change my shape creating to using convex hull it will not crash again but i think convex hull is not as good as btBvhTriangleMeshShape. anyone have any suggestions?
i also have to mention that collision between rigid bodies works fine.
Post Reply