Open stefnotch opened 1 year ago
Here is another demo example highlighting the issue (the example must be registered first in the all_examples3.rs file):
https://gist.github.com/YouSafe/6f49c4c35e65a0edfa0d06f1a7915514
It is just a moving cube which has a position-based kinematic rigid body moving back and forth and the usual kinematic character controller from the testbed.
The behaviour when gravity is applied to the character controller:
The behaviour when no gravity is applied to the character controller:
I hope this demo better visualizes the issue!
Thanks for providing these examples. The character-controller not being pushed when its desired movement is zero is by-design (because of the early-exit identified by @stefnotch) to save computation times. But, clearly, it’s not the behavior anybody expects in practice, so we can consider this as a bug.
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 https://github.com/dimforge/rapier/blob/89e3d7650c84f96893376a79cbc120aeaeb74785/src_testbed/testbed.rs#L765 , which effectively disables gravity. So, when not pressing any keys, then the entire vector that is passed to move_shape will be
[0.0, 0.0, 0.0]
. And then, the bug can be reproduced.cargo run --bin all_examples3
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. https://github.com/dimforge/rapier/blob/89e3d7650c84f96893376a79cbc120aeaeb74785/src/control/character_controller.rs#L215
(The stairs logic also has some "skip if zero" logic, but I think that's unrelated)