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?
I changed few things in your PG:
- 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
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.
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));
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.
Did you try with
I’m not sure what you want to achieve actually
What do you want to do in the
inputMap code branch?
inputMap should rotate/ strafe left. But im not sure if setEuler works correctly.
It should rotate the character (sphere) and change the walkDirection that way. Like strafe left/ strafe right in most common games.
I get it !
1st, typo on quaternion, then once the basis orientation is changed, update the forward/backward direction
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 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
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