A high-performance, physics-based character controller for PlayCanvas that provides smooth movement, jumping, slope handling, and moving platform support.
Screen.Recording.2025-07-19.at.5.21.23.PM.mp4
- Slope Handling: Automatic slope detection and sliding on steep surfaces
- Moving Platforms: Full support for moving and rotating platforms
- Collision Detection: Robust collision handling with walls, corners, and ceilings
- Ground Snapping: Automatic ground detection when falling
- Air Control: Configurable air movement control
- Input Agnostic: Provide your own input logic. Keyboard control example included
- Jumping: Configurable jump speed with optional continuous jumping
- Stairs: Hover height allow for adjusting max climbable stair
- Debug Visualization: Optional debug rendering for collision detection
- Important: Use the included
ammo.js
files instead of PlayCanvas's built-in version, as the PlayCanvas version is outdated and may cause compatibility issues. - Shape Casting: The controller requires
convex-cast.js
as PlayCanvas does not natively include shape casting functionality at the time of writing.
- Copy the
kcc/
folder to your PlayCanvas project - Copy the
Ammo/
folder to your project (contains the required ammo.js files)- Uncheck
Preload
on ammo.js - Set
Name
toAmmo
underWASM MODULE
forammo.wasm.wasm
- Set
Glue script
toammo.js
andFallback script
toammo.wasm.js
- Uncheck
- Add the scripts to your character entity:
kcc.mjs
- Main controller scriptkccInputDesktop.mjs
- Desktop input handling
- WASD: Movement
- Mouse: Look around (yaw rotation)
- Space: Jump
- Shift: Sprint (increases speed by
sprintScalar
)
Attribute | Default | Description |
---|---|---|
speed |
6 | Walk speed in m/s |
gravity |
-9.81 | Gravity acceleration in m/s² |
jumpSpeed |
6 | Initial jump velocity in m/s |
airControl |
1 | Air movement control (0-1) |
radius |
0.5 | Controller collision radius in meters |
maxIterations |
5 | Maximum collision resolution iterations |
slopeLimitDeg |
50 | Maximum walkable slope angle in degrees |
skin |
0.01 | Collision skin thickness in meters |
groundSnap |
0.3 | Ground snapping distance in meters |
hover |
0.2 | Hover distance above ground when grounded |
debug |
false | Enable debug visualization |
Attribute | Default | Description |
---|---|---|
lookSpeed |
0.5 | Mouse look sensitivity |
sprintScalar |
2.0 | Speed multiplier when sprinting |
continuousJump |
false | Enable continuous jumping while holding space |
The controller uses a two-pass collision resolution system with the collide & slide algorithm:
- Vertical Pass: Handles gravity, jumping, and ground detection
- Horizontal Pass: Handles player movement and wall collisions
- Optimized collision detection with configurable iteration limits
- Efficient vector math operations
- Minimal memory allocation during runtime
// Access the controller from your input script
const kcc = entity.script.kcc;
// Set input manually
kcc.setInput(horizontal, vertical, jump, yawDelta);
- Character falls through ground: Increase
groundSnap
value or check collision layers - Stuck on slopes: Adjust
slopeLimitDeg
orskin
values - Poor performance: Reduce
maxIterations
or disable debug visualization - Physics errors: Ensure you're using the included ammo.js files, not PlayCanvas's built-in version
Enable the debug
attribute to visualize:
- Controller collision sphere
- Grounded state (blue = grounded, red = not grounded)
- Collision raycasts
- Hit points and normals
Feel free to submit issues, feature requests, or pull requests to improve the controller.