Search code examples
unity-game-engine2dgame-physics

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


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.

Ball: Ball Rigidbody2D & Collider2D screenshot components, Ball physics material screenshot

Walls: Wall Collider2D screenshot

Video showing the balls(starts at 0:06) https://www.youtube.com/watch?v=fIo84AMMbgI&feature=emb_logo

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.

Solution

  • A guy on Unity forum told that the balls stop at walls might be the Physics2D.velocityThreshold set above zero. We checked and it solved the issue that balls stop X movement near walls. He also said box2d works only approx so maybe no way to make balls bounce 100% precise. So maybe I will have to forget about 100% bouncy balls.