dimforge / bevy_rapier

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

Perpetual jitter/contact clip bouncing with angular velocity #254

Open atlv24 opened 1 year ago

atlv24 commented 1 year ago

Minimal reproduction

I think there might be some scheduling weirdness with the default rapier3d setup, it seems that angular velocity is being applied to rotation after contact resolution for that frame, or maybe i misunderstand how render updates vs physics updates are being run. the behavior i am observing is that

Setup

A dynamic convex hull resembling a ball is a few units above a flat static floor. A dynamic cone is a few units above the hull, a bit off-center. Gravity will pull both objects down towards the floor.

Expected behavior

There is an initial linear impact of the hull against the floor. The hull is perfectly balanced on its tip. The cone falls and hits the hull off-axis. The hull topples as it gains angular velocity. Another side of the hull hits the floor and does not visibly clip into the floor because contact resolution is complete before the frame is rendered. Some of the hull's energy is lost in the process. Eventually both the hull and the cone lose all energy and stop moving, and get marked asleep.

Observed behavior

Initial linear impact behaves correctly. The hull topples over as the cone hits it off-axis and gains angular velocity. The hull momentarily clips into the floor and renders that way for at least a frame before bouncing back out and correcting, with as much or more energy as before. The hull gets stuck in an infinite micro-angular-bouncing loop and jitters perpetually. Neither the cone nor the hull get marked asleep.

No combination or Restitution/Friction/Dampening or erp value adjustments seems to fix this.

rparrett commented 1 year ago

This repro could be even simpler by spawning the hull with an initial angular velocity and getting rid of the cone setup.

The behavior is also easier to observe with an orthographic camera.

Vrixyz commented 2 months ago

The linked reproduction no longer reachable, is it still an issue ?

atlv24 commented 1 month ago

I changed my username, the url is now https://gist.github.com/atlv24/1c524f734cc109946f12a4294a2f5b5e