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.

5 Likes

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

1 Like

Yo @arcman7 … I got full havok physics working for Babylon Toolkit. Including all the Unity Colliders. Even Terrain Collider that uses heightfield shape.

I am working on a new Raycast Vehicle and Character Controller re-written from scratch using the awesome Havok Physics Plugin

Unity Interactive Content - Character Controller Demo Playground

3 Likes

This is awesome, working right now, but I’m gonna check this out more thoroughly later tonight - Sick work man!

@MackeyK24 dude, aside from the physics being buttery smooth, the scene and the animations are also nicely done - this is a super cool demo :sunglasses:

Thanks :pray:

1 Like

It’s basically to show usage of the interactive content you can create with Unity Exporter.

then dynamically attaching a player controller script. Which you can always write your on script and get references to the Animation State and Character Controller components to move and animate your character

1 Like