fix: add fixed timestep accumulator to prevent energy drift in BouncingBall - #344
Conversation
|
@iamjaysingh is attempting to deploy a commit to the PhysicsHub's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Thank you for this fix, this applies also on the other simulations with the same issue? |
Hi @mattqdev! Yes, the same fix can be applied to the other simulations The fix is the same pattern — adding a fixed timestep accumulator to each |
|
I'd like to have one PR for fixing everything, do you think you can fix this issue in a centralized way (i mean, not changing every simulation file)? |
Yes absolutely! I can implement the fixed timestep accumulator centrally |
…gy drift across all simulations
Hi @mattqdev! I've updated the fix to be centralized in Time.js instead The fixed timestep accumulator (FIXED_DT = 1/120s) is now built directly Tested on all three affected simulations:
Let me know if you'd like any changes! |
|
Thank you! Is also Parabolic Motion fixed? |
Yes! ParabolicMotion also uses computeDelta() so it automatically |
|
Alright, perfect! Thank you! |
|
🎉 This PR is included in version 3.29.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Fixes #226
Root Cause
The BouncingBall simulation was using a variable timestep (real wall-clock
delta time) for physics integration. When frame rate varies — due to tab
switching, browser throttling, or display refresh inconsistencies — the
variable dt causes energy drift in the Euler integration, making the ball
lose or gain height on each bounce even at damping = 1.
Fix
Added a fixed timestep accumulator pattern to BouncingBall.jsx:
Testing