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:

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.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Character controller cause crash

Post by benelot »

Hello again,

What do you mean by ConvexHull is not as "good" as TriangleMeshShape? What is good and what is bad here? If you can represent your object using convex hull shape, this will be of higher performance than using any concave shape. Furthermore, from the docs: The btBvhTriangleMeshShape is a static-triangle mesh shape, it can only be used for fixed/non-moving objects (http://bulletphysics.org/Bullet/BulletF ... Shape.html). So this shape is not meant to be moved around in case you want that (as in a character). It is probably important to know that you do not have to use the same character model for both graphics and physics. For characters, it usually suffices to model the body of it as one or multiple spheres to have something to run against.
peymankop
Posts: 6
Joined: Wed Nov 02, 2016 4:05 pm

Re: Character controller cause crash

Post by peymankop »

benelot wrote:Hello again,

What do you mean by ConvexHull is not as "good" as TriangleMeshShape? What is good and what is bad here? If you can represent your object using convex hull shape, this will be of higher performance than using any concave shape. Furthermore, from the docs: The btBvhTriangleMeshShape is a static-triangle mesh shape, it can only be used for fixed/non-moving objects (http://bulletphysics.org/Bullet/BulletF ... Shape.html). So this shape is not meant to be moved around in case you want that (as in a character). It is probably important to know that you do not have to use the same character model for both graphics and physics. For characters, it usually suffices to model the body of it as one or multiple spheres to have something to run against.
by bad i mean it isn't as accurate as btbvhTrianglemesh i think! if you have some source code on what is the best way to create collision shapes for static objects share with me thank you.
no,i do not use bvh for my character controllet,i use it for my ground object. the ground isn't moving and it is static in my program.
Post Reply