请观看此短视频以了解问题所在。一旦有大约 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 Granbergs 寻路项目 http://arongranberg.com/astar/
谢谢
最佳答案
我收到了 A* 寻路项目的作者 Aron 的回复。
添加光线转换修改器将进一步提高性能。
免费版只支持一个线程,专业版最多支持8个线程。
关于unity3d - Unity A* 寻路项目 : Repath makes the character move to the opposite direction,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34008700/