Avoid Land Collisions with Bullet

I am trying to use the Bullet physics engine to create a 3D world.

I have my character with a Capsule shape on his body, and my earth, made of some static blocks, is glued together, here is a diagram illustrating my words: enter image description here

The problem arises when my character starts from one block to another: Bullet detects a collision, and my character starts to jump a little along the y axis.

How can i avoid the problem?

+6
source share
2 answers

What I did to overcome this problem:

Instead of putting the capsule on the ground, I had a dynamic capsule ride on top of spring. I implemented spring as a few rays originating from the bottom of the capsule. Spring was half a meter or less, and she pulled and pushed the capsule to and from the ground. Traction / traction is important so that the character does not jump unexpectedly. The stiffness of the springs controls how strong you are.

It had the following effects

  • No unwanted collision with the edge of the geometry on the floor as the capsule floats
  • Walking along the stairs and slopes is implicit. spring will simply "step" up the stairs and push the character capsule up.
  • Hopping is simply a matter of releasing a grip on the ground, which was spring, and giving the body an impulse.
  • A boarding character after jumping or falling automatically displays a "bend of the knee", as you expected.
  • Pleasant smoothing of vertical movements in general. As on elevator platforms, etc.
  • Due to capture / pulling to the ground, even when you run downhill, the character will not start to “fly”, as you experience in some games (I find this usually annoying).
  • Ducking character = reduce spring and / or capsule length.
  • Gliding downhill? You can completely control it by checking the angles of the floor area of ​​the rays that hit the spring hit.

I had to deal a lot with spring stiffness, spring length, grip length, etc., but in the end I was very pleased with how simple it worked, but it worked well.

+14
source

Your calling challenge is "Internal Border Collision." I just found a solution a few hours ago. If you are using btHeightfieldTerrainShape for your world, then you should use btBvhTriangleMeshShape to solve this problem.

Here's the answer.

Add this callback:

static bool CustomMaterialCombinerCallback(btManifoldPoint& cp,const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1) { btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1); return true; } extern ContactAddedCallback gContactAddedCallback; 

Then create btBvhTriangleMeshShape and add this code where pGround is your btBvhTriangleMeshShape :

 // Enable custom material callback pGround->setCollisionFlags(pGround->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); btTriangleInfoMap* triangleInfoMap = new btTriangleInfoMap(); btGenerateInternalEdgeInfo(pGroundShape, triangleInfoMap); 

Or you can open the InternalEdgeDemo example in Bullet to find out how to implement it in detail.

0
source

Source: https://habr.com/ru/post/974644/


All Articles