BabylonJS
BabylonJS Character Controller V2
Full character controller in BabylonJS — keyboard + gamepad input, blend tree animations, collision, camera follow. Drop-in reusable system.
Rebuilt from scratch after V1 had animation blending issues and tight mesh-name coupling. Works with any GLB using standard Mixamo/RPM bone naming.
Architecture
Two modular classes: AnimCtrl (skeletal animation blend tree) and CharCtrl (input + physics). Config consolidated in DEFAULT_CHAR_CONFIG — one place for all tunable values.
Features
- Input: keyboard + gamepad unified through the same action map
- Animations: blend tree smoothly transitions Idle → Walk → Sprint with weight lerping
- Physics: capsule collider (stable, no mesh-collider jitter), slope alignment, squash-and-stretch on landing
- Camera: adaptive lerped follow, dynamic FOV expansion at higher speeds, mobile framing adjustments
- Mobile: glassmorphism virtual joystick, settings persisted via localStorage
- Crouch + sprint: operate as toggles that coexist (high-speed crouched running works)
Asset pipeline
Uses the FBX2GLB batch tool — animations merged and optimized into a single compressed GLB.
V1 → V2
| V1 | V2 | |
|---|---|---|
| Input | Keyboard only | Keyboard + Gamepad |
| Collider | Mesh | Capsule |
| Animations | Start/stop | Blend tree |
| Coupling | Tight to mesh names | Config-driven |