Multiple Targets?

Is there any way to create a path which would go to a set of targets in a specific order? E.g. going to four corners of a room in a specific order.

[Snip] Good call Aron! Was not really thinking there XP

What Burdock answered will usually work. However, if you are using multithreading (more than one thread), the paths can get calculated in arbitrary order (well, roughly sorted, but two threads can calculate paths in parallel, so they can be slightly reordered when returned).

There is an example in the docs for accomplishing this: http://arongranberg.com/astar/docs/_waypoint_path_8cs-example.php

And a script showing example usage: http://arongranberg.com/astar/docs/_waypoint_path_tester_8cs-example.php

What if I have a scenario where I want an NPC in my 2D top-down game to have a “daily routine”, i.e every day it has 43 targets I want it to reach. And when it reaches a target I set it’s new Target or do some other action. Is this possible?

I thought about something like saving an Array of Vector2 positions, and when the NPC arrives to one, I set the next. But to do this I would need to:

  • Somehow turn a Vector into a Transform to work with your Target.
  • Somehow be able to tell when my NPC has reached it’s target, so that I can run a method.

Hi

In the latest beta there is a script called ‘Patrol’ which you can simply attach to one of your agents (and make sure it doesn’t have the AIDestinationScript as well). This script will take a list of Transforms that the agent will move to in order and it will optionally wait for a while at each point.
In the beta the destination of an AI is now a Vector3 instead of a Transform, so you should easily be able to tweak this script to take a list of Vector2 positions instead.

Here is the complete script for future reference: https://pastebin.com/ZB4Kp720, however that file should also exist if you download the 4.1 beta (it also requires the beta unfortunately, so you cannot use it in 4.0.x).

One thing you may have to account for is what to do if the AI cannot reach the destination at all. It will try to move as close as possible, however you may have to use some game specific check to see if is actually reached a point close enough to do whatever task you had set out for the NPC.

Hi, great to hear that it’s in the beta. This is not a time-sensitive issue so I’ll probably just wait until it’s in production :slight_smile:

PS, have you thought of releasing a “lite” version, for us that would like to support but cannot afford the full price?

I think having a free version and one pro version is enough for now. Having more versions involves a lot more work in making sure they all work, and I’d rather keep it simple for now.