我如何让敌人只在 x 轴上统一看玩家
how do i make an enemy look at a player only on the x axis in unity
public mouselook mouselook;
public float speed = 20.0f;
public float minDist = 1f;
public Transform target;
public Transform enemylocation;
// Use this for initialization
void Start()
{
// if no target specified, assume the player
if (target == null)
{
if (GameObject.FindWithTag("Player") != null)
{
target = GameObject.FindWithTag("Player").GetComponent<Transform>();
}
}
}
// Update is called once per frame
void Update()
{
if (target == null)
return;
// face the target
enemylocation.LookAt(target);
public void SetTarget(Transform newTarget)
{
target = newTarget;
}
我在网上看了大约一个小时,我尝试植入一个向量 3,但没有成功。谁能帮忙?
我希望敌人只在 x 轴和 z 轴上看玩家(目标),而不是在 y 轴上看,因为它使它漂浮。是否还有一种方法可以让它看到播放器 - 10 倍或类似的东西?/提前致谢!
我猜你只是想偏航敌人,这可以在目标与敌人处于同一水平时实现。
var p = target.position;
p.y = enemylocation.position.y;
enemylocation.LookAt(p);
public mouselook mouselook;
public float speed = 20.0f;
public float minDist = 1f;
public Transform target;
public Transform enemylocation;
// Use this for initialization
void Start()
{
// if no target specified, assume the player
if (target == null)
{
if (GameObject.FindWithTag("Player") != null)
{
target = GameObject.FindWithTag("Player").GetComponent<Transform>();
}
}
}
// Update is called once per frame
void Update()
{
if (target == null)
return;
// face the target
enemylocation.LookAt(target);
public void SetTarget(Transform newTarget)
{
target = newTarget;
}
我在网上看了大约一个小时,我尝试植入一个向量 3,但没有成功。谁能帮忙? 我希望敌人只在 x 轴和 z 轴上看玩家(目标),而不是在 y 轴上看,因为它使它漂浮。是否还有一种方法可以让它看到播放器 - 10 倍或类似的东西?/提前致谢!
我猜你只是想偏航敌人,这可以在目标与敌人处于同一水平时实现。
var p = target.position;
p.y = enemylocation.position.y;
enemylocation.LookAt(p);