At the moment using a grid graph, AI lerp (2D) and Dynamic grid obstacles for recalculating when blocks are destroyed/moved.
Is there a way to start the agent movement only when the path to player is possible, since now it moves to closest possible point and gets stuck looking stupid, before any blocks are broken down by the player and route to player can be completed? Thank you in advance!
(no option for the pro version for now)
Not sure if there’s a better way to do this, but I got this working on my end by checking if the endPoint is within a certain distance of the target. If it doesn’t end at the target, I can then stop the agent and do some other alternative action.
public void TestPathTraversal(GameObject target){
ABPath testPath = ABPath.Construct(transform.position, target.transform.position);
GetComponent<Seeker>().StartPath(testPath, CanPathBeTraveresed);
void CanPathBeTraveresed(Path p){
float threshold = .5f;
if (Vector3.Distance(testPath.endPoint, target.transform.position) < threshold) {
Debug.Log("This agent's path will end at the target!");
}
}
}
I’m sure there’s a better way to do this, but this does work pretty well. (You also don’t have to construct a whole new path like I did, you can use the one the agent generates)
Thank you this seem to be working for my case! Where do you call the canPathBeTraversed in AILerp i assume?
CanPathBeTraversed
is used in a callback after the path is finished being created:
GetComponent<Seeker>().StartPath(testPath, CanPathBeTraveresed);
That way, no matter whether the path took a long time to calculate or not, that method will be called directly afterwords. You can find more information about that method and argument here
It’s probably also worth mentioning that the CanPathBeTraversed
method is local to TestPathTraversal
! I don’t want to sound like I’m insulting your abilities or anything, that’s just something I would’ve totally 100% missed myself unless I wrote it
Thanks this was actually very helpful! and no worries I’m very beginner in gamedev so your comments were totally needed!!
Awesome! Glad to help then Best of luck and let us know if you need any more help!
Hey there! Wanted to make a quick note! The method I wrote above works, however I also wanted to add that there’s also PathUtilities.IsPathPossible
that I forgot all about haha.
I’d say use PathPossible just to see if they can get there at all, but if you wanted to check more than if it’s possible to get there, you can use the method I wrote above