- Home /
Set an angle for bouncing
I don't know how to ask this question properly. I'm making a pong game, and I have the problem that sometimes the bounce direction of the padle is way too up or down, making it bounce like in the picture, so it takes a while to reach the other player. Is there a way to set a maximium/minium angle for the ball to move? Like, "don't go higher than (30, 30) and lower than (30, -30)"?
Thank you!
I'm using unity build in bounce physics.
pong.jpg
(87.4 kB)
Comment
Answer by NEOF · Jul 14, 2015 at 09:49 AM
What I would do is changing the x velocity to a minimum x velocity for the ball. Code would look like this:
if (Mathf.ABS(ball.rigidbody.velocity.x)<minX))
{
ball.rigidbody.velocity=new Vector3((ball.rigidbody.velocity.x<0)?-minX:minX,ball.rigidbody.velocity.y,ball.rigidbody.velocity.z);
}
That is it.
Your answer
![](https://koobas.hobune.stream/wayback/20220611231153im_/https://answers.unity.com/themes/thub/images/avi.jpg)