A* Pathfinding Project

Only get Path in a Vector3 array


#1

hey, im new here;) and have like some other noobs a problem.

i use the project “rts engine” from unity store. the project handles allready all i need but i try to use A* with it. The only thing i need is a array with Vector3 in it (aka the path) the rest i can handle.
i make an emty with the A* mainscript and set up the grid and so on. all works pretty well. i try to get the path via seeker and in other ways but allways i have to do it with an event. is there a direct way?

in a method wich is called once from “rts engine” to find a path

public bool CalculatePath(Vector3 targetPosition){

Vector3array = ???

return true;

}

i try to get there a array(Vector3) from A* without to assign to an event. i like to have it right now so the method should wait until the path is calculatet or something similar

i dont know if u mean what i want? my english is not so good…:frowning:


#2

Hi

Yes, you can do something like

public List<Vector3> CalculatePath(Vector3 targetPosition){
    var path = seeker.StartPath(transform.position, targetPosition, null);
    path.BlockUntilCalculated();
    if (path.error) throw new System.Exception();
    return path.vectorPath;
}

See also https://arongranberg.com/astar/docs/path.html#BlockUntilCalculated


#3

Perfect! thank you.

I knew there was an easy way.