Pass precalculated paths to pathfinder


#1

I am writing a game with many entities in which I am trying to squeeze as much performance out of as possible. I have also noticed that sometimes the paths created are not straight lines, which for most scenarios is fine for me but not for cases when the AI is close to the player.

I am already doing linecasts for the AI to determine sight of the player. In this instance, I would like to pass the seeker/AstarPath/AIPath the line as the path without doing any other calculation. Is this possible?


#2

I am considering extending the Seeker class with a SetPath method that just does CancelCurrentPathRequest and OnPathComplete.

Edit: This approached worked. If there is an obviously better method please let me know.


#3

This approach will not work because it would be very awkward to deal with corners. I am instead going to create a StraightLinePath will will be requested in this condition, which will use spatial awareness additionally to optimize the process, and then optimistically create a path directly, only doing any modifications when unwalkable nodes are found.


#4

That ended up being much more simple to implement by creating a custom heuristic that considers the distance from the passed line.


#5

Hi

Seems you have managed to solve the issue now. I’d just like to highlight that the movement scripts (AIPath/RichAI/AILerp) have a SetPath method which I think should do roughly what you want.