Breakout-style ball getting stuck horizontally...

Hey everyone...

I'm making a Breakout/Arkanoid-style ball and paddle game, but I'm stuck on one part of the ball behaviour. My ball is bouncing around the way I want using physics and no gravity, but every once in a while the ball will get stuck on the x-axis and bounce back and forth on that one axis only. How can I detect if it's only moving a very little distance on the y-axis and then give it a bump on the y to force it back into normal play?


If you are using a rigidbody to model the behaviour, you could check for the velocity using `collider.attachedRigidbody.velocity` and since `velocity`is a Vector3, you can check only for the velocity on the y-axis.

I had given up on trying to find the answer to the problem(“ball stays on one axis”) and created my own solution.


I duplicated the walls and created four prefabs(leftbent, rightbent, topbent, and bottombent) then in function Start() instantiated these walls positioning them outside of the viewing area rotating each wall by 4 degrees, then inside function FixedUpdate(), check to see if velocity equals 0.5 or less on either the X or Y axis.

if velocity is equal to Zero on the X axis topbent and bottombent get positioned into view
if velocity is equal to Zero on the Y axis leftbent and rightbent get positioned into view

P.S. Unity3D Games Coming Soon! to Innovative Creations Software’s line of products

hope this helps everyone in the Unity3D community

Al, Floyd

this works fine for me:

if((rigidbody2D.velocity.y < min_y_velocity) && 
(Mathf.Sign(rigidbody2D.velocity.y) == 1))
    	rigidbody2D.AddForce(new Vector2(0, 5f));
else if((rigidbody2D.velocity.y > -min_y_velocity) && 
(Mathf.Sign(rigidbody2D.velocity.y) == -1))
   rigidbody2D.AddForce(new Vector2(0, -5f));

after this, you have to re-set the complessive max speed with another method