How to have correct 2D balls bouncing of the walls physics? And also so it works same with low fps?

Hello guys,

I would like to have 2D bouncy balls physics.
It is with Unity Physics 2D. I set bounciness 1 and friction 0.
I tested it on flat floor and here are issues I see:

  1. The balls keep jump higher and higher.
  2. Balls stuck at the wall. Skip to 0:40 you’ll see there are several balls lose their X movement and stay vertically at the right wall.

Video showing the balls(starts at 0:06)

What should I do? to have

  1. That balls don’t start to jump higher and higher. I tried to set less bouncy like 0.99 but it works different with lags on lower fps. So it seems not a solution.
  2. That balls don’t lose their X movement of the walls.
1 Like

Physics runs during the fixed-update and is frame-rate independent so it won’t have any effect on it at all. What will have an effect is if you’re performing work per-frame or in a way that isn’t frame-rate independent.

The lack of bounce is probably the Velocity Threshold which, as the docs state, any collisions with a relative linear velocity below this threshold will be treated as inelastic (no bounce). Set this to zero should solve that assuming this is your issue.

The 2D physics system (Box2D) doesn’t conserve energy perfectly with a bounce of 1 and it can vary depending on various factors. It’s approximate only.

1 Like

Thanks MelvMay!

Velocity Threshold solved the problem with balls stop at walls.

As for the 100% bounce. I guess will have to deny from the idea of 100% bouncy balls.

However. Is there a way to make a ball to want to jump? Not sure how to explain.
Like the ball want to jump at some minimum force. So for example the bounciness set to 90% and a ball jumps less and less speed. But when the speed is lower than a certain threshold then the ball thinks “That is lower than the minimum so I want to jump higher”.

This way when the jump force will become less then a ball will increase it, so this way will generate something like balance situation where the ball jumps around the same force.

You can do this but it’s obviously custom behaviour. Either modify the velocity yourself upon contact using a Dynamic body and callback or use a Kinematic body and detect collisions yourself using queries (CircleCast maybe) then you can perform your own response as you like.

1 Like

Thanks so much for the help, MelvMay!
Will look into those.