【发布时间】:2019-08-12 21:09:13
【问题描述】:
我的游戏有一个关卡,敌人飞入并在游戏中发射导弹,他们应该在被射击的那一刻瞄准当地的玩家,但当他们被射击时,他们只会在玩家向左移动时击中玩家对,当它向前移动时,导弹就从头顶飞过。
void Start() //targeting the player
{
playerManager = GameObject.FindGameObjectWithTag("PlayerManager").transform; //NB: it is tracking wherever the playerManager is placed on the X axis, but NOT the playerManager directly
//target = new Vector3(playerManager.position.x, playerManager.position.y); //this is the original line
// target = new Vector3 (playerManager.transform.position); //this was recommended on unity answers but it returns an error.
rb.velocity = transform.forward * speed; //addition, tells it to shoot forward
}
我希望导弹在沿 z 轴移动时继续瞄准玩家。
当玩家只能左右移动时,它会按预期工作,但当他们向前移动时,导弹最终会飞过头顶。
这一行:target = new Vector3 (playerManager.transform.position);返回以下错误信息:
错误 CS1729 'Vector3' 不包含采用 1 个参数的构造函数
【问题讨论】:
-
就目前而言,您已经获得了玩家变换,然后您将导弹“向前”发送,但向前可能不会朝向玩家... vector3 因为它建议需要 3 个点,x,y ,z....尽管您似乎没有在代码中使用玩家位置,因此它前往玩家的机会似乎很低