fix: contain ball in ball bounce simulation. #190
fix: contain ball in ball bounce simulation. #190petercr wants to merge 2 commits intophysicshub:mainfrom
Conversation
…ment to prevent tunneling. - Fix ceiling collision position calculation by removing redundant radius addition - Add hard containment checks to prevent ball from escaping bounds at extreme velocities - Update sitemap URL for pendulum blog post
|
Hey bro thank you so much for this, unfortunately you'll have to resolve some conflicts cause I'm working on a completely new system for like almost of the simulations, so when I will push my changes you a i'll have to fix that. |
|
Hey man I'm sorry to tell you this, but as I announced in Discussion and on Discord, I've pushed some changes I've been wanting to make for weeks. So, in addition to a lot of other bugs, there are some conflicts that need to be resolved. Can you see if you can fix the conflicts? Sorry for this. |
|
@physicshub are you talking about conflicts on this branch or another branch? It's fine if you don't use this PR as well. I will message you on the discord for more details on the bugs. |
|
Yeah I mean the conflicts that were created on this branch with my commits. |
🔍 Description
This PR fixes two issues in the BouncingBall simulation:
1. Fix ceiling bounce position calculation (line 64)
The ceiling collision was incorrectly positioning the ball after bounce. When the ball hit the ceiling, the formula
newPos.y = radius + collisionPenetrationwas adding the radius twice, causing the ball to jump too far down after bouncing.Before:
newPos.y = radius + collisionPenetrationAfter:
newPos.y = collisionPenetrationNow the ball correctly bounces at the proper mirror position.
2. Add hard containment for high-velocity balls (lines 84-105)
When damping (restitution) is set above 1.0, the ball gains energy on each bounce and can reach extreme velocities (e.g., 10³⁹ m/s). At these speeds, the ball can "tunnel" through boundaries in a single frame and escape the canvas.
Added a hard containment check that:
Files Changed
app/(core)/constants/Utils.jsTesting
✅ Checklist
Before requesting a review, please ensure that you have:
npm run dev)📂 Type of Change
🧩 Additional Notes for Reviewers
The ball doesn't get super charged and escape the canvas anymore.
Basically it stop just before it would reach the velocity needed to escape.