问题是在代码中
shooter = GameObject.FindObjectOfType<Player>();
shooterPosition = shooter.transform.position;
direction = (shooterPosition - transform.position).normalized;
自从
shooter.transform.position
是玩家的位置和位置
transform.position
那子弹的位置呢
shooterPosition - transform.position
给你一个向量,直接从子弹的位置指向玩家的位置。
听起来你想做的是给子弹增加一些不准确度(如果我错了,请纠正我)。你可以用这样的东西来做(我假设这是2D?)
shooter = GameObject.FindObjectOfType<Player>();
shooterPosition = shooter.transform.position;
direction = (shooterPosition - transform.position).normalized;
// Choose a random angle between 0 and maxJitter and rotate the vector that points
// from the bullet to the player around the z-axis by that amount. That will add
// a random amount of inaccuracy to the bullet, within limits given by maxJitter
var rotation = Quaternion.Euler(0, 0, Random.Range(-maxJitter, maxJitter));
direction = (rotation * direction).normalized;