Description
Issue
We have a moving kinematic rigidbody. And this rigidbody can push our KinematicCharacterController around. As in, the character controller gets lushed away when something moves into it.
However, when we call move_shape
with different desired_translation, then it behaves unexpectedly.
-
Calling it with desired_translation = [0.0, -9.81, 0.0], which is gravity. Then, we get pushed by our moving body. Expected.
-
Calling it desired_translation = [0.0, 0.0, 0.0], which is zero. Then, we no longer get pushed by our moving body. Instead the moving body goes straight through our character controller. Unexpected.
Steps to reproduce
Remove
Line 765 in 89e3d76
[0.0, 0.0, 0.0]
. And then, the bug can be reproduced.
- Remove that line of code
- Start testbed
cargo run --bin all_examples3
- Switch to character controller
- Move in the way of the moving platform
- When not pressing any key, then the moving platform will move into the character controller.
all_examples3_2023-04-24-0292.webm
Our setup in our game where we noticed it
We have a rigidbody with a box collider, which is KinematicPositionBased. We're moving that rigidbody back and forth. (rigid_body.set_next_kinematic_translation(...);
)
We have a floor, which is one big box collider.
We have a KinematicCharacterController, which mostly just follows the examples from the documentation. We're supplying it with a desired_translation
every frame. And then we use the returned effective movement to move the character controller.
Additional notes
Apparently the while loop in rapier's character controller gets skipped when passed a zero vector.
rapier/src/control/character_controller.rs
Line 215 in 89e3d76
(The stairs logic also has some "skip if zero" logic, but I think that's unrelated)