How to setup Ammo KinematicCharacterController

Hi,
i am trying to get the Ammo KinematicCharacterController to work with my Babylon Project.
I must do something wrong, because the KinematicCharacterController does not collide with other meshes in my scene. Here is a example where it should collide with the ground mesh: Ammo Kinematic Character Test

Any idea what i missed?

Regards
Stefan

pinging @Cedric

Let me check that :slight_smile:

I changed few things in your PG:

  • gravity
  • shape size
  • controller step height
    and more importantly, I’ve added a call to controller.setUseGhostSweepTest and added flags combination to addCollisionObject to support for characters:

CharacterFilter = 32 and DefaultFilter = 1,StaticFilter = 2

https://playground.babylonjs.com/#Q3RVQC#12

From my experience, ammo character controler can be tricky to set up. If your use case can fit with simple sphere rigid body, I’d go for it. You might end up with slightly more code to handle jumps for example but it will be easier to maintain.

3 Likes

Hi @Cedric, thanks for helping out!

Now i can walk back and forth, but im still struggling to get the rotation to work.
In the bullet examples they update rotation by:

btMatrix3x3 orn = m_ghostObject->getWorldTransform().getBasis();
orn *= btMatrix3x3(btQuaternion(btVector3(0,1,0),yaw));
m_ghostObject->getWorldTransform ().setBasis(orn);

But that does not work with ammo.js, because Ammo.btMatrix3x3() is no constructor.

Do you know a workaround for this? I just prepared another playground that shows the problem.

https://playground.babylonjs.com/#Q3RVQC#15

Kind Regards

Stefan

Did you try with btMatrix3x3.setEulerZYX ?

Yes… trying to: https://playground.babylonjs.com/#Q3RVQC#16

I’m not sure what you want to achieve actually :slight_smile:
What do you want to do in the inputMap[65] code branch?

inputMap[65] should rotate/ strafe left. But im not sure if setEuler works correctly.

something like this ?
https://playground.babylonjs.com/#Q3RVQC#17

It should rotate the character (sphere) and change the walkDirection that way. Like strafe left/ strafe right in most common games.

I get it ! :slight_smile:
1st, typo on quaternion, then once the basis orientation is changed, update the forward/backward direction

https://playground.babylonjs.com/#Q3RVQC#18

Great! I made some progress too. I added some Ammo extensions provided by Ammo.lab (MIT licence) that adds some math to handle things a bit easier.

So this is almost working perfect now. But the walkdirection is somehow calculated wrong. Actually its moving to the opposite direction. So far idk wh: https://playground.babylonjs.com/#Q3RVQC#19

your PG doesn’t load. I get an error with undefined line 96

This does the same now: https://playground.babylonjs.com/#Q3RVQC#21

This is really weird. It seems that the rotation is mirrored somehow. When i turn left it walks right. But this makes no sense since the box turns right.

IIRC there was some switch in quaternion format between ammo and the rest of the world where w is sent as 1st parameter.

It looks like it works but I suggest you to confirm the quaternion construction parameters

https://playground.babylonjs.com/#Q3RVQC#22

also you can try to use BABYLON.Vector3.RotationFromAxis and get axis from the transform.

Thanks! This works much better, but its moving overhead now: https://playground.babylonjs.com/#Q3RVQC#23

sorry there was an error in the last version, this one loads on the playground: https://playground.babylonjs.com/#Q3RVQC#24