Support Forum

How to only go X amount of nodes towards target?

I’m using AILerp in my grid-based game and my enemies have a walk speed that should only allow them to move a maximum number of nodes per turn.

Is it possible to set this anywhere? I’m guessing I would need to add all of the nodes in the path to an array and set an index as the new destination.

if you are doing something so different than maybe you should create a custom movement script as I’m fairly certain it would be quite hard to modify AILerp to work like that because it is doing some sort of predictive movement (asking for points ahead of itself on the path)

Will do, thanks.

I guess the more general question would be how can I obtain the nodes to a target in an array? Would I get that info from AILerp or Seeker?

Edit: I found this post from 2013 asking essentially the same thing. Is there a function for that now?

the calculated Path object in the tutorial has a .path variable that is a list of all of the graph nodes used in the calculated path, and .vectorPath is the list of vector positions to be followed

I was able to get a Vector3 list from that, thank you.

Last question, is it possible to get that path without StartPath? The goal is to get that list first, select an index from it, then do StartPath with that index.

not as far as I’m aware as the vector3 list is the calculated path, though you could easily enough just go through part of the list and stop at whatever point instead of the end

since the path to each node/position in the list is optimal

also just realized that you probably shouldn’t use any modifiers such as simple smooth or raycast as those alter your paths and change the number of points per node

I think I got it, thanks for your help! For anyone else who needs it, just make sure the speed variable on AILerp is set to 0

public List<Vector3> pathList;
public Vector3 pathTarget;
public GameObject target;

IEnumerator MoveOnGrid(int walkDistance){
	seeker.StartPath(transform.position, target.transform.position, OnFirstPathComplete);
	yield return new WaitForSeconds(.1f);
	pathTarget = new Vector3(pathList[walkDistance].x, pathList[walkDistance].y, pathList[walkDistance].z);
        seeker.StartPath(transform.position, pathTarget);
        gameObject.GetComponent<AILerp>().speed = 3;
}

public void OnFirstPathComplete (Path p) {
        Debug.Log("Yay, we got a path back. Did it have an error? " + p.vectorPath);
        pathList = p.vectorPath;
}