Hi there, I’m quite new to Unity but regarding the A* Pathfinding Project, I wanted to know how I can achieve multiple destinations.
I’m making a map which is in 2D and in that map there will be a player icon and bunch of locations (Using Buttons). So the player icon will not move until I press one of the buttons and whichever one I click will then move the player to that location.
I’m assuming I need to do some extra coding in the AIDestinationSetter script but really have no idea how.
Thanks
1 Like
Hi
I would recommend not using the AIDestinationSetter at all and doing something like this:
// Or RichAI or AILerp depending on which movement script you are using
public AIPath ai;
void WhenButtonClicked(Vector3 target) {
ai.destination = target;
// Forces the ai to recalculate its path immediately
ai.SearchPath();
}
Thank you so much, I had to use Transform instead of Vector3 or Vector2(since it didn’t work with those) but it seems to work well enough with what you have provided.
By the way I just wanna squeeze one more question here and that is on how to stop/halt the ai movement while its moving to its destination. ill be using a ui button to tell the ai to stop moving.
Again thank you for your help and quick response.
That depends on the semantics you want.
setting
ai.isStopped = true;
Will make it stop, but you can make it resume its movement if you set ai.isStopped = false.
If you want to clear the path and make it forget everything its destination then use
ai.SetPath(null);
ai.destination = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
Cheers man, I didn’t think it all the way through and you had the foresight to mention both of things that I will require.
I am getting the hang of it now, it seems that most things are in AIPath, I discovered things like ai.reachedEndOfPath which would be handy for if statements etc.
Gonna experiment some more and once I feel like I have a good bearing, I will purchase the pro version of this. Thanks again.