Following a tutorial, I have created a ball that bounces along 3 walls with a paddle at the bottom, like the game Pong. Sometimes the ball gets stuck in a straight line bounce loop, bouncing from one wall to the other and back with no variation. I’d like to add a bit of randomness to the bounce angle to the ball so that it doesn’t get stuck.
I found a similar question answered already, but it was answered with C#, and the tutorial script is in javascript. Everything I tried did not work. Would Random range and vector help? I don’t know how to implement them into the script.
Part of the script added to the ball:
function Awake(){
rigidbody.AddForce(8, 4, 0, ForceMode.Impulse);
InvokeRepeating("IncreaseBallVelocity", 2, 2);
}
function IncreaseBallVelocity(){
rigidbody.velocity *= 1.05;
}