General use Dynamic Character Controller for Ammo.js

This playground is setup in Typescript, but the controller itself works just fine in normal JavaScript for those unfamiliar; you’ll just need to remove the types.

Ammo.js is notoriously badly documented, but I took sometime to understand the underlying collision filtering system, as well as some useful concepts and techniques such as raycasting and object re-use within the Ammo.js. JavaScript API.

Raycasting - line 455
Raycasting closest not me - line 451 & 125
Object re-use - line 465

I made an effort to stay true to the DynamicCharacterController.cpp source code originally written by the Ammo.js author kripken

There are however some differences such as substituting the closest not me raycasting class with normal raycasting that uses collision group filters instead. But overall I think this character controller is pretty performant.

Atm, the controller will detect when the player collides with something horizontally, but there’s nothing being done with that detection. It could be used for pushing blocks, and other game related logic.


this is great! I’ve been looking for some examples for ammojs and bjs. thanks a ton.

1 Like