Unity3d 自顶向下2d 4方向ai
嗨,我想用unity和csharp为我的游戏创建一个ai 我不知道如何去做,我希望人工智能移动在4个方向,所以如果球员是对角线从它将下降,然后左ect 这是我尝试过的,但它只有在我移动时才会移动,而且它不会向左或向右转弯Unity3d 自顶向下2d 4方向ai,unity3d,artificial-intelligence,Unity3d,Artificial Intelligence,嗨,我想用unity和csharp为我的游戏创建一个ai 我不知道如何去做,我希望人工智能移动在4个方向,所以如果球员是对角线从它将下降,然后左ect 这是我尝试过的,但它只有在我移动时才会移动,而且它不会向左或向右转弯 void OnTriggerStay2D(Collider2D other) { if (other.CompareTag("Player")) { if (transform.position.y < other.gameObject.
void OnTriggerStay2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
if (transform.position.y < other.gameObject.transform.position.y)
{
rigidbody2D.transform.position += Vector3.up * speed * Time.deltaTime;
anim.SetBool ("Backwards", true);
}
if (transform.position.y > other.gameObject.transform.position.y)
{
rigidbody2D.transform.position += Vector3.down * speed * Time.deltaTime;
anim.SetBool ("Front", true);
}
if (transform.position.x > other.gameObject.transform.position.x)
{
rigidbody2D.transform.position += Vector3.left * speed * Time.deltaTime;
anim.SetBool ("Left", true);
}
if (transform.position.x > other.gameObject.transform.position.x)
{
rigidbody2D.transform.position += Vector3.right * speed * Time.deltaTime;
anim.SetBool ("RIght", true);
}
}
}
void OnTriggerStay2D(碰撞的r2d其他)
{
如果(其他比较标记(“玩家”))
{
if(transform.position.yother.gameObject.transform.position.y)
{
rigidbody2D.transform.position+=Vector3.down*速度*时间.deltaTime;
anim.SetBool(“前”,真);
}
if(transform.position.x>other.gameObject.transform.position.x)
{
rigidbody2D.transform.position+=Vector3.left*速度*时间.deltaTime;
anim.SetBool(“左”,真);
}
if(transform.position.x>other.gameObject.transform.position.x)
{
rigidbody2D.transform.position+=Vector3.right*速度*时间.deltaTime;
anim.SetBool(“右”,真);
}
}
}
也许你应该先看看一些基本教程。搜索谷歌,因为有很多很好的教程可以学习基础知识。在问这个问题之前,我已经看了几遍了。我真正需要知道的是,我如何让人工智能知道如何向下移动到玩家z,然后移动到他的x,但我不知道如何做,每次只控制一个轴。检查玩家x位置是否小于或大于敌人x位置,然后移动它。在你的x轴位于正确的点之前,不要继续到z轴。好的,这是有意义的。我会看看我是否可以尝试,我会问我是否需要在我尝试的上面添加帮助,但它不起作用