dimforge / dimforge/bevy_rapier
Strange KinematicCharacterControllerOutput behaviour
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 282
- PR merge metrics
- No merged PRs in 30d
Description
Sorry for the vague title, I'm really not sure how to word this succinctly.
I'm trying to make a basic 2D character controller with gravity and collisions. For this, I decided to use the provided `KinematicCharacterController` and `Velocity` components to handle collisions and movement respectively.
I don't know if it's something I've done wrong, but `grounded` keeps flickering between `true` and `false` every couple of frames if I reset `linvel.y` while not grounded, even when the player collider is nowhere near the ground collider. If you wait for it to fall through, it no longer flickers.
I've put together [a gist](https://gist.github.com/Pyroglyph/af8f397ade524929c37a1866d343e343) that illustrates the problem.
If you Check the console you'll find something like this repeated over and over:
```
Grounded: true Velocity: [0, 0]
Grounded: false Velocity: [0, 0]
Grounded: false Velocity: [0, -9.81]
Grounded: false Velocity: [0, -19.62]
Grounded: false Velocity: [0, -29.429998]
Grounded: true Velocity: [0, -39.239998]
```
If you remove Line 47 (the line resetting `linvel.y`), the flickering stops, but the colliders still pass through each other instead of colliding.
Extra notes:
- I've noticed that if I set `linvel.y` to a negative value (down) instead of resetting it to zero, `grounded` stops flickering when the player reaches the ground, but then slowly sinks down into it.
- The issue also happens when using a fixed timestep, if that helps.
- The issue still happens when using the `Ccd` component.
- `KinematicCharacterController.snap_to_ground` does nothing to help.
Am I doing something wrong? I thought something like setting the Y velocity to 0 when on the floor would be a relatively simple thing to do.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.