dimforge / bevy_rapier

Official Rapier plugin for the Bevy game engine.
https://rapier.rs
Apache License 2.0
1.26k stars 259 forks source link

Dynamic RigidBody getting stuck in corners #487

Open jhgarner opened 7 months ago

jhgarner commented 7 months ago

I have a setup with a single dynamic RigidBody on top of a floor and inside of 4 walls all of which have no friction. The dynamic RigidBody is moved by directly adjusting its velocity. I expect the RigidBody to slide around the room between the walls smoothly, but instead it appears to get hung up in corners. I've created a small example showcasing the problem: https://github.com/jhgarner/bevy-physics-repro/tree/main. The example code is in src/main.rs. You can use cargo run -- broken and the arrow keys to move the cube around and see the strange behavior. You can also run the repo with cargo run -- working which will create a slightly smaller RigidBody which doesn't get stuck and moves smoothly. I can't figure out why the slightly larger one exhibits the issue while the smaller one doesn't.

Here's a recording from running the example with cargo run -- broken: broken.webm

And here's a recording from running the example with carg run -- working: working.webm

Is there a different setup I should be using for something like this?

Vrixyz commented 5 months ago

I'm noting there has been a few versions released since the report, it would be interesting to know if this is still happening with an updated reproduction

jhgarner commented 5 months ago

I'm still seeing the issue after updating to the latest versions (I've pushed the latest versions to the example repo).

I think the issue might come from Parry? Since creating this bug, I gave Xpbd a try and saw similar problems. I also tried experimenting with my own physics system + Parry .14's time of impact functions and saw weird behavior when the aabbs were touching or moving such that they'd end up touching. If I remember right, Parry would report no collision on really small velocities when the objects actually ended up touching. I ended up copying https://tavianator.com/2011/ray_box.html for toi calculations and constraining my game to simpler physics objects. There was a lot changing in my code then though so take this analysis with a grain of salt.