Firstly I LOVE the package, I am almost 100% going to buy it once I flush out some issues I am having.
I am making a zombie game just to mess around with the pathfinding and have a ‘Target Position’ that the zombie actors are attempting to get too.
I have lightweight zombie actors that launch their own thread which updates every 2 seconds.
IEnumerator MoveToTarget(float waitTime) { while(true) { seeker.StartPath (transform.position, TargetPosition.position, OnPathComplete); yield return new WaitForSeconds(waitTime); } }
Then their ‘FixedUpdate’ uses the same code from your simple tutorial.
`
public void FixedUpdate ()
{
if (path == null) {
//We have no path to move after yet
return;
}
if (currentWaypoint >= path.vectorPath.Count) {
Debug.Log ("End Of Path Reached");
return;
}
//Direction to the next waypoint
Vector3 dir = (path.vectorPath[currentWaypoint]-transform.position).normalized;
dir *= speed * Time.fixedDeltaTime;
controller.SimpleMove (dir);
//this.transform.rotation = Quaternion.Lerp(this.transform.rotation, Quaternion.LookRotation(path.vectorPath[currentWaypoint]), 3.0f);
RotateTowards(path.vectorPath[currentWaypoint]);
Debug.Log (path.vectorPath[currentWaypoint]);
//controller.transform.Rotate(24,24,24);
//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;
}
}
`
Fairly straight forward, no messy computation. The problem is when calculating a new route, there is EXTREME lag when I have 30 zombies or so on the scene. Is this just a limitation of this project or is there something wrong with the way in which I am re-calculating the paths? I wanted to make a game with atleast 40/50 zombies on the scene at the same time but with this lag it struggles with 20.
Note that there are also other problems when some actors wont even calculate their paths and will just ‘Path fail’ for some ticks until it works all of a sudden… I am guessing this is related to your method of queuing paths?
Thanks!