ineedahero
ineedahero

Reputation: 527

Unity bouncing ball miraculously gains height

I have a sphere with bounciness set to 1

enter image description here

The ball has no drag and uses gravity

enter image description here

It hits a platform, which has bounciness set to 1 and no friction

enter image description here

Yet, the ball bounces higher on every bounce, going to infinity. How is such a thing possible, when I have not given it any extra momentum?

Upvotes: 0

Views: 1361

Answers (2)

CosmicGiant
CosmicGiant

Reputation: 6441

The issue comes from the fact that physics in games happens in discrete frames, and that a moving object will be "inside" another at the frame where there is a collision. The physics engine then has to separate the objects before the next frame, and figure out how much energy to "bounce" with.

One of the steps to do this involves figuring out how much the objects overlap, and that's where this phantom extra energy is comin from. Less error in the overlap equals less error in the energy.

Don't fiddle with the bounciness; those are naive solutions, not to mention they sidestep the issue rather than solving it.

What you should do is to fix what's wrong with your collisions. That can be done a number of ways, the most appropriate/performant of which depends on each specific game:

  • Increase your physics frame rate (decrease fixed delta time). This reduces overlaps and makes physics frames "smoother". It doesn't really solve phantom energy though; only makes it's causes and effects smaller (maybe so small they become unnoticeable, which is all you need).
  • Set your sphere's collision detection method to Continuous Dynamic, and set your ground to static. If you need the sphere to collide with other stuff, those other stuff present similar issues, and those need to be non-static, set their rigidbodies' collision detection method to Continuous. (This is the method I most often find to be the best, but I've had projects where others were better for various reasons)
  • Increase your Default Solver Velocity Iterations
  • Change your solver type to Temporal Gauss Seidel

Upvotes: 4

Mr.Goat
Mr.Goat

Reputation: 26

I have had a similar issue with javascript/html/css canvas animations. I have no explanation for this. Use a number like 0.99999 or 0.969399 and that should do the trick. I do get what you mean though it's weird. Just get close to 1. That's all I can say. I hope this helps anyway.

Upvotes: 0

Related Questions