Im working on a brickout clone and the ball eventually gets stuck horizontally. All the ball does when this happens is going left to right hitting the side bumpers at a stable Y x.xx point. I know its stuck because the number does not change on the Y but it only changes on the X(going left to right)
any suggestions welcome to give some force to the ball avoiding it from getting stuck in the same position
I was thinking if the position Y does not change for lets say 20 seconds then push it down a bit. Im just not sure how to make that type of condition
You can create a timer and reset it when a brick is hit. If the timer was ever over a specified value, you would take action. But as an alternative, why not give the ball a bit of (random?) force each time it hits the side walls…simulate a bit of imperfection in the walls and/or ball. In OnCollisionEnter() if the object it hit was a side wall do:
Rigidbody.AddForce(Random.insideUnityCircle * random_force_factor);
Note this assumes the game is being played on the X/Y plane. You will have to swap some values around if the game has a different orientation. I don’t believe it will take much force to keep the ball from being stuck.