-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restitution 1.0 produces higher bounce every time. #1286
Comments
Hello, This is a known issue and has been discussed before, see: godot-jolt/godot-jolt#374 (comment) It is something I should look into though (at least confirm that other physics engines don't have this behavior / don't do the opposite of slowly losing energy). |
Hi, thanks for answer. Here is test from Bullet. App_ExampleBrowser_8CBJGR0Tk2.mp4Open Dynamics Engine demo_tracks_EwlCLPDUta.mp4Unity build-in engine Unity_46nul3Ab2c.mp4 |
Flax Engine (Physx 5) FlaxEditor_zkI0mj6H2n.mp4So seems I was wrong about "other engines" but at the same time rebouns at the same height makes more sense to me. At this point if you belive there is no bug I think it could be just declarated as expected behaviour and closed. |
I'll leave the bug open for now. It's definitively not physically correct. I'll see if there's a way to make this better. Mainly for future me, I've simplified the simulation loop to: // Code to simulate a sphere of radius 2 falling from 10 units high
Vec3 pos = Vec3(0, 10, 0);
Vec3 vel = Vec3::sZero();
Vec3 g(0, -9.81f, 0);
float dt = 1.0f / 60.0f;
float maxy = 0;
for (int i = 0; i < 1000; ++i)
{
// Apply gravity
// Equivalent to PhysicsSystem::JobApplyGravity
vel += g * dt;
// If we're penetrating the ground, we have to reverse the velocity (corresponds to restitution 1).
// Equivalent to PhysicsSystem::JobSolveVelocityConstraints
float penetration = 2.0f - pos.GetY();
if (penetration > 0 && vel.GetY() < 0.0f)
vel = -vel;
// Update position
// Equivalent to PhysicsSystem::JobIntegrateVelocity
pos += vel * dt;
// Record new height records (note we only trace when we're going down again to avoid tracing multiple lines for the same bounce)
if (vel.GetY() <= 0.0f && pos.GetY() > maxy)
{
maxy = pos.GetY();
Trace("Simulated new high: %f", maxy);
}
} which produces:
When simulating the same setup in Jolt we get the exact same results:
Implementation: SimpleTest.zip As said in the other ticket: When the collision has been detected, the gravity has been applied already so the bounce velocity is overestimated. |
When I set everything to 0.0 but 1 rigid body to restitution 1.0 every next bounce goes higher. Is it intended behaviour? Usually, it is bouncing on the same height in other physics engines.
git patch with example
0001-restitution-bug.patch
The text was updated successfully, but these errors were encountered: