In my breakout clone I'm trying to split the ball, at which point they assume random directions to move in. This direction is decided in the Start() of each ball instance. Upon observation is seems that the more balls I split, the more obvious it becomes that all balls move in the same direction, towards the upper-right corner of the screen. Can anyone help? Why are the values the same every time the balls split? This is my code:
// Use this for initialization
void Start ()
{
ballRB = transform.rigidbody;
direction = new Vector3(0,1,0);
//If there's only one ball in the field, being this current one, the default up motion should be used.
if (GameObject.Find("StartBall").GetComponent<StartBall>().numBalls <= 1) ballRB.AddForce(direction*1000f, ForceMode.Force);
//If not, there are more balls, which means the player split the ball. A random direction should be used in this case.
else ballRB.AddForce(GenerateRandomDirection(), ForceMode.Force);
}
Vector2 GenerateRandomDirection()
{
int randX = Random.Range(0,360);
int randY = Random.Range(0,360);
randDirection = new Vector2(randX, randY);
return randDirection;
}
Aucun commentaire:
Enregistrer un commentaire