Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 一直在尝试制作基于人工智能的轮流策略游戏_C#_Unity3d_Artificial Intelligence - Fatal编程技术网

C# 一直在尝试制作基于人工智能的轮流策略游戏

C# 一直在尝试制作基于人工智能的轮流策略游戏,c#,unity3d,artificial-intelligence,C#,Unity3d,Artificial Intelligence,我已经可以通过寻路创建移动网格,并为玩家避开障碍物。现在我想让AI根据移动网格和可用的动作点移动(就像玩家那样),但我不知道怎么做。现在,我只能让角色移动到这个位置(但它不能跟随寻路,这个角色应该是AI)。我一直在努力解决这个问题,但无法解决。你们能帮帮我吗?谢谢 以下是我到目前为止得到的代码(它使假定为AI的角色移动到该位置,但不遵循寻路): 使用UnityEngine; 使用系统集合; 公共类玩家:玩家 { 无效唤醒() { moveDestination=transform.positio

我已经可以通过寻路创建移动网格,并为玩家避开障碍物。现在我想让AI根据移动网格和可用的动作点移动(就像玩家那样),但我不知道怎么做。现在,我只能让角色移动到这个位置(但它不能跟随寻路,这个角色应该是AI)。我一直在努力解决这个问题,但无法解决。你们能帮帮我吗?谢谢

以下是我到目前为止得到的代码(它使假定为AI的角色移动到该位置,但不遵循寻路):

使用UnityEngine;
使用系统集合;
公共类玩家:玩家
{
无效唤醒()
{
moveDestination=transform.position;
}
//用于初始化
void Start()
{
颜色变换器();
}
//每帧调用一次更新
无效更新()
{
}
公共覆盖无效更新()
{
如果(GameManager.instance.currentPlayerIndex==5)
{
if(矢量3.距离(移动目的地、变换位置)>0.1f)
{
transform.position+=(moveDestination-transform.position).normalized*moveSpeed*Time.deltaTime;

if(Vector3.Distance(moveDestination,transform.position)那里没有寻路代码。这只是一个过于复杂的lerp。同样,直接移动到该位置会导致图形化避障的严重问题

你最好的选择是实现一个基于网格的navmesh,并使用类似于a*搜索的方法来查找路径。移动将限于相邻的方块,因此不会发生图形化的障碍物回避


看一看。它将为您提供所需的一切,除了为玩家移动设置动画和目标位置的游戏逻辑。

那里没有用于寻路的代码。它只是一个过于复杂的lerp。此外,直接移动到该位置将导致图形化避障的主要问题

你最好的选择是实现一个基于网格的navmesh,并使用类似于a*搜索的方法来查找路径。移动将限于相邻的方块,因此不会发生图形化的障碍物回避

看一看。它会为你提供你所需要的一切,除了动画玩家的移动和目标位置的游戏逻辑

using UnityEngine;
using System.Collections;

public class AIPlayer : Player
{
    void Awake()
    {
        moveDestination = transform.position;
    }

    // Use this for initialization
    void Start()
    {
        ColorChanger();
    }

    // Update is called once per frame
    void Update()
    {

    }


    public override void TurnUpdate()
    {
        if (GameManager.instance.currentPlayerIndex == 5)
        {
            if (Vector3.Distance(moveDestination, transform.position) > 0.1f)
            {
                transform.position += (moveDestination - transform.position).normalized * moveSpeed * Time.deltaTime;

                if (Vector3.Distance(moveDestination, transform.position) <= 0.1f)
                {
                    transform.position = moveDestination;
                    actionPoints--;
                }
            }

            else
            {
                moveDestination = new Vector3(2 - Mathf.Floor(GameManager.instance.mapSize / 2), 1.5f, -2 + Mathf.Floor(GameManager.instance.mapSize / 2));
                GameManager.instance.NextTurn();
            }
        }

        base.TurnUpdate();
    }

    public override void TurnOnGUI()
    {

    }

    public override void ColorChanger()
    {
        base.ColorChanger();
    }
}