[Help] Random.range doesn't add speed on average... right

I think I misunderstand something, but I am not sure. In this lecture they show the code:

Vector2 Tweak = New Vector2 (Random.Range(0f, 0.2f), Random.Range (0f,0.2f))
Then they add this Tweak to the velocity of the rigidbody of the ball.

The instructor remarks that this on average adds 0.1 velocity to your ball every time it bounces and might on the long run result in a very fast ball.

But this can’t be correct? Assuming the ball moves equally often left as right and down as up than half the time the balls slows down because of this function? (Since you would add force in the opposite direction as it’s going?). Am I missing something here or is the instructor simply mistaken in saying the ball speeds up?

I was thinking the same thing. My solution is to do Vector2 Tweak = New Vector2 (Random.Range(-0.2f, 0.2f), Random.Range (-0.2f,0.2f)), which seems to work fine.

Privacy & Terms