Skip to content

Improve KCC examples and use MoveAndSlide#949

Merged
Jondolf merged 7 commits into
mainfrom
kcc-examples-mns
Mar 4, 2026
Merged

Improve KCC examples and use MoveAndSlide#949
Jondolf merged 7 commits into
mainfrom
kcc-examples-mns

Conversation

@Jondolf

@Jondolf Jondolf commented Mar 4, 2026

Copy link
Copy Markdown
Member

Objective

Fixes #273

#894 implemented the move-and-slide algorithm for building kinematic character controllers. However, our KCC examples don't actually use it yet! To demonstrate how it can be used, and have better KCC examples for Avian, we should update the examples.

Solution

Use MoveAndSlide for the kinematic_character_2d and kinematic_character_3d examples. This involved some tricky bits:

  • Slope climbing and sliding is handled in the on_hit callback. This is the most complicated part. I partially adapted the logic from Rapier.
  • The callback also tracks collisions. Contact forces are applied to dynamic bodies in a separate system.
  • I really struggled to get characters not to slide down walkable slopes when standing still. This turned out to largely be a bug in cast_move; the skin width wasn't considered in the shape cast max_distance, causing the character to move past the skin width, at which point depenetration kicked in, moving the character along the normal, causing drift down the slope. This is now fixed.

I also improved the examples in general:

  • Added TransformInterpolation
  • Changed scheduling to collect inputs in PreUpdate and handle movement in FixedUpdate
  • Added terminal velocity
  • Made the component split a lot more sensible and got rid of bundles
  • Made damping use exponential decay like LinearDamping does

Testing

Ran the examples a bunch of times.


Showcase

kinematic_character_3d

2026-03-04.02-09-58.mp4

Previously, the box would fly away as soon as you stand on it or push it into a wall. With move-and-slide and manually applied impulses, this doesn't happen.

Jondolf added 7 commits March 4, 2026 00:50
- Use `MoveAndSlide`
- Combine a bunch of components for a more sane split
- Make system scheduling more sane
Previously, move-and-slide constantly let objects go past the skin width, and depenetration kicked in. This was causing sliding down slopes due to depenetration!
@Jondolf Jondolf added this to the 0.6 milestone Mar 4, 2026
@Jondolf Jondolf added C-Bug Something isn't working C-Examples Improvements or additions to examples D-Modest A moderate level of difficulty: suitable for simple features or challenging fixes A-Character-Controller Relates to character controllers labels Mar 4, 2026
@Jondolf Jondolf merged commit 4a92d33 into main Mar 4, 2026
6 checks passed
@Jondolf Jondolf deleted the kcc-examples-mns branch March 4, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Character-Controller Relates to character controllers C-Bug Something isn't working C-Examples Improvements or additions to examples D-Modest A moderate level of difficulty: suitable for simple features or challenging fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collision between the character and the square in the kinematic_character_2d is wonky

2 participants