gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:31:29 24 4
gpt4 key购买 nike

请观看此短片以了解问题所在。一旦有大约 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com