Skip to content

Kinematic Character Controller move_shape clips through objects when desired_translation is zero #485

Open
@stefnotch

Description

@stefnotch

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

desired_movement -= Vector::y() * speed;
, 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.

  1. Remove that line of code
  2. Start testbed cargo run --bin all_examples3
  3. Switch to character controller
  4. Move in the way of the moving platform
  5. 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.

while let Some((translation_dir, translation_dist)) =

(The stairs logic also has some "skip if zero" logic, but I think that's unrelated)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions