unity3d - Unity A* 寻路项目 : Repath makes the character move to the opposite direction

标签 unity3d path-finding a-star

请观看此短片以了解问题所在。一旦有大约 23 个字符,它们就会开始向不同的方向移动。请帮助我,我正在尽我最大的努力搜索了好几天并尝试了不同的寻路方法,但都没有成功。

http://screencast.com/t/sUx9O0I9GQ

我的设置是一个网格,角色有一个带有默认配置组件的 AIPath。肯定是可以的,因为我在压测视频里看到了:https://www.youtube.com/watch?v=htoen7x3LuQ

这行代码导致了问题:

seeker.StartPath (transform.position,target.transform.position, OnPathComplete);

完整的上下文

public void Start () {
    InvokeRepeating ("searchPath", 1.0f, 1.0f);
    searchPath ();
}

public void searchPath() {
    GameObject target = GameObject.Find ("Target");
    seeker = GetComponent<Seeker>();
    controller = GetComponent<CharacterController>();
    //Start a new path to the targetPosition, return the result to the OnPathComplete function
    seeker.StartPath (transform.position,target.transform.position, OnPathComplete);
}

public void OnPathComplete (Path p) {
    Debug.Log ("Yay, we got a path back. Did it have an error? "+p.error);
    if (!p.error) {
        path = p;
        //Reset the waypoint counter
        currentWaypoint = 0;
    }
}

public void Update () {
    if (path == null) {
        //We have no path to move after yet
        return;
    }
    if (currentWaypoint >= path.vectorPath.Count) {
        Debug.Log ("End Of Path Reached");
        Destroy(gameObject);
        return;
    }
    //Direction to the next waypoint
    Vector3 dir = (path.vectorPath[currentWaypoint]-transform.position).normalized;
    dir *= speed * Time.deltaTime;
    controller.SimpleMove (dir);
    //Check if we are close enough to the next waypoint
    //If we are, proceed to follow the next waypoint
    if (Vector3.Distance (transform.position,path.vectorPath[currentWaypoint]) < nextWaypointDistance) {
        currentWaypoint++;
        return;
    }
}

正如标题所说,这是 Aron Granberg 的寻路项目 http://arongranberg.com/astar/

谢谢

最佳答案

我得到了 A* 寻路项目的作者 Aron 的回复。

Hi

This is due to a high load on the pathfinding system. An agent might request a path when it is at some point, but since it takes some time for the path to be calculated, the agent will have moved when it gets the result back. The AIPath script tries to fix this (assuming the closestOnPathCheck field is enabled) but it cannot do it at all times. The solution is to reduce the load on the pathfinding system and the game. First, make sure you have multithreading enabled (A* Inspector -> Settings), also it is probably a good idea to turn off Show Graphs for larger graphs since drawing that is pretty slow and will reduce the fps significantly. You can also increase the pickNextWaypointDistance and the forwardLook fields on the AIPath script, that will reduce the chance of this happening.

添加光线转换修改器将进一步提高性能。 免费版仅支持一个线程,专业版最多支持 8 个线程。

关于unity3d - Unity A* 寻路项目 : Repath makes the character move to the opposite direction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34008700/

相关文章:

unity3d - 在多个监视器中打开多个 Unity 应用程序

algorithm - 使用 IDDFS 创建路径数组

ios - A* 仅在某些情况下有效

c# - 统一的 Firebase 远程配置仅获取默认值而不是真实值

c# - 在斜坡上以相同的速度移动球 - Unity 3D

c++ - 递归算法的实现

xna - 如何优化 A* (AStar) Search for Concave Shapes? (包括截图)

search - 选择不扩展节点还是不将其添加到 A* 中具有探索的封闭集的队列中,这重要吗? (图搜索)

c++ - 机器人路径规划 - A*(星级)

c# - 玩家拿起物体时触发声音