Implementing A* path in old 3D project

Hi Aron,
I purchased A* Pro and have been reading the documentation occasionally when time permits, but I don’t understand how to tie the pathfinding into my AI. I have enemy units with decision trees that need to move to certain locations based on a few conditions. I don’t quite understand how to call “Seeker.StartPath()” from my custom script. Can you provide a mock example?

For example, let’s say in my script I have the condition:

if (temperature < 10)
goInside = true;

How do I have the seeker script make the agent go inside the house prefab, and once it’s inside then I need it to stop and remain until (temperature > 10)

I’ve played around with your example scenes but they don’t address what I’m needing to do. I don’t have point and click AI in my game. I just need them to travel where I need them to go without any interaction at all. Thanks

Hi

I would recommend that you use one of the built in movement scripts (e.g. AIPath) and then you set the ai.destination property to wherever you want the AI to go. So for example

if (goInside) {
   ai.destination = house.position;
} else {
   ai.destination = outside.position;
}

Make sure that you do not also have an AIDestinationSetter component attached, because that will otherwise override whatever destination you set from your scripts.

1 Like

Ok this makes sense. Also, is there a way to do multpile houses so I can just use tags and have the ai choose the closest one instead of a set target prefab? I want to have dynamic cover points around the map.

Hi

To pick the closest building you can use the MultiTargetPath path type (https://arongranberg.com/astar/docs/multitargetpath.html), however that requires you to disable the built in path recalculation and some other things, to be able to use it with the AIPath movement script. Usually it is much easier (and faster, and usually accurate enough) to simply move towards the closest building based on the straight line distance.

Ok thanks Aron, for now that will suffice.

1 Like