我正在为我的项目使用arongranberg A * Pathfinding。 如果我离他太近,基本上敌人会跟随我的玩家。
正如你在这里看到的那样,敌人的(蓝色人)运动并不像我预期的那样顺畅。
以下是移动检测和动态路径请求的代码。
void checkPosition(){
currentPosition = transform.position;
if (previousPosition == null) {
previousPosition = transform.position;
}
else {
if (currentPosition.x > previousPosition.x) {
moveRight ();
} else if (currentPosition.x < previousPosition.x) {
moveLeft ();
}
if (currentPosition.y > previousPosition.y) {
moveUp ();
} else if (currentPosition.y < previousPosition.y) {
moveDown ();
} else if (currentPosition.x == previousPosition.x && currentPosition.y == previousPosition.y) {
//stopNow ();
}
previousPosition = currentPosition;
}
}
IEnumerator UpdatePath(){
seeker.StartPath(transform.position, target.position, OnPathComplete);
yield return new WaitForSeconds (1f/updateRate);
StartCoroutine (UpdatePath ());
}
我可以做些什么来改善它?