Handling Ammo Kinematic Character Controller

Yo @JohnK and @trevordev … I need your help with handling the ammo.js kinematic character controller.

I got it to create but when i call setWalkDirection or jump nothing happens…

Am i supposed to some how tick some kind of character controller update function


Am i supposed to on every frame, somehow get the position of the Ghost Object which should be the guy getting moved around in the physics world. So am i supposed to be manually updating the physical babylon mesh representation of that game object… or What ???

Can one you guys please Help Me :slight_smile:

FYI… Here what i got going so far:

const worldMin:any = Ammo.btVector3(-1000,-1000,-1000);
const worldMax:any = Ammo.btVector3(1000,1000,1000);
this.m_overlappingPairCache = new Ammo.btAxisSweep3(worldMin, worldMax);

const collisionShape:any = this._abstractMesh.physicsImpostor.physicsBody.getCollisionShape();
const startTransform:any = new Ammo.btTransform();
startTransform.setOrigin(new Ammo.btVector3(0.0, 0.0, 0.0));

this.m_ghostObject = new Ammo.btPairCachingGhostObject();
this.m_overlappingPairCache.getOverlappingPairCache().setInternalGhostPairCallback(new Ammo.btGhostPairCallback());


const stepHeight:number = 0.35;
this.m_character = new Ammo.btKinematicCharacterController(this.m_ghostObject, collisionShape, stepHeight);

this.m_character.setWalkDirection(new Ammo.btVector3(0,0,10));

Sorry but reading your posts about Ammo.js you have surpassed my knowledge. All I did was was a re-working of some three.js code. Hopefully trevordev can help.

Do you have a playground/fiddle setup (Like this one https://jsfiddle.net/t0xwbgLa/)? Are you already calling world.stepSimulation(1/60, 10); to move other things? Yea the physics world and babylon world are separate so when rendering you need to copy pos/rot of objects in the physics world

I figured it out… to update the Babylon object position from a ghost pair cache object… I register after step function on impostor and set the motion state world transform from ghost object get world transform… now works

Problem is … I did all that and finally got kinematic character controller to work to find out it kinda sucks compared to a good dynamic character controller

Plus if you put more than 1 btKinematicCharacterController in scene… it just kills the frame rate.

But implementing a good dynamic character controller performs way better… so I am going with a dynamic character controller instead

1 Like

Yo @trevordev … Bro… I can be such a DUMBASS sometimes…

It turns out the whole time i was still setting a Babylon Physics Impostor on when try to create a Kinematic Character Controller… That is why was so slow and could not put more than one chracter controller in the scene… The Ghost Objects and Kinematic Character Controller that get manually added to the physics world was fighting with the original Babylon physics imposter (btRigidBody)

I fixed that and it runs kinda sweet … Using Native Bullet Ghost Objects Is The SHIZZ NIT

Especially for collision detection… has is own overlapping pair cache you can iterate all its contact points…

According To Bullet Guys:
The best way to determine if collisions happened between existing objects in the world, is to iterate over all contact manifolds. This should be done during a simulation tick (substep) callback, because contacts might be added and removed during several substeps of a single stepSimulation call.

Check Out Ghost Object Collision in this link

Anyways… Back to the Kinematic Character Controller… Which is supposed to use much less resouces NOT using rigidbodies nd it has its own bullet kinematic gravity and is grounded detection … I am in love with the native Ammo Physics API…

Cant wait to try out the Vehicle Physics Stuff :slight_smile: