在我的突破克隆中,我试图分裂球,此时他们假设随机方向移动。这个方向在每个球实例的Start()中决定。在观察时似乎我分开的球越多,所有球朝着屏幕的右上角向相同方向移动就越明显。有人可以帮忙吗?为什么每次球分裂时值都相同?这是我的代码:
// 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;
}
答案 0 :(得分:0)
对不起伙计们,我不小心放入了度数(0到360),所以结果总是积极的。 问题解决了。