addforce velocity changes speed
Hi Unity
I have this code attached to a ball, it's a Pong clone. Everything works fine, BUT the speed the ball moves is completely random every time.
rb.velocity = new Vector2(Random.Range(10, -10), Random.Range(10, -10) 5f Time.deltaTime);
I've adjusted the numbers a lot of different ways but can't fix this. What I assumed was two randoms return a float for the X and Y respectively which determines which direction the ball flies, then the force multiplier of 5f will determine how fast this will go.
Always seems to randomly change speed with addforce too, it has a rigidbody2d
EDIT:
Hi again Unity, I have been thinking about this. I think what the problem is this, here's my theory: The addforce or velocity changes it's speed depending on the distance. It will move faster to reach it's target if the random.range passes it 20,20 than 5,0. Is this correct? It would explain why the speed is different every time it goes.
Anyway, I think the solution is to use something like insideUnitCircle.
Thanks for your help.
Your answer
