Multiple objects - One path

Hey!
I’m making a tower defense and heard that the A* pathfinding Project is perfect for artificial intelligence. I’ve tried it, i’m stunned. A really good Project :slight_smile: So i’m starting to get acustomed to the workflow that this project requires ; the seeker, the Astar path script , etc. I’m a bit confused. I’ve read all the “Getting started” tutorial, and i’m ok with what is learned in it. But is it possible to have one object that does not move but generates a path (with the Aipath script) and that multiple objects follow this path (and not all at the same time) ? Imagine I have three spawn areas in my tower defense map. So I have three “pathgenerators” , one for each spawn area. Then , each ennemy that spawn (in a specified spawn area, but at a random place in that same spawn area) follows the path related to its spawn area .In that way , I have a very limited amount of path generating on the runtime (imagine I have 1000 ennemies, I have as many pathgenerators as spawnareas, so something between 1 and 10 , instead of 1000 ennemies who tries to find their unique path - which could be hard for the cpu and all , and easily avoidable with what i’m trying to do) . I also update the graph ( a grid graph) at runtime, when I place a new tower. So that’s not a problem.
I’ll show you an image to make it easier to understand :slight_smile:

If the image doesn’t work ; cl.ly/image/1M0e141l2D2d
Thank you for reading, and maybe answering :wink:

if your tower defense is a maze ( tower can be spawn anywhere ), this couldn’t work. Imagine that you spawn a tower on a cell located at the middle of your C Path, but some ennemies were following this path, and futhermore, some ennemies are on first part of C Path and some are right behin your new spawned tower …

A new C path should be recalculated for a group of ennemies but not for the others …

Hi

The best path for you would be to use the FloodPath which I wrote specifically to handle this scenario.
Check the docs for it, you will find an example on how to use it. The only thing you would need to do would be to issue a FloodPath request at start and every time the graph changes. One nice thing about the FloodPath is that you aren’t even restricted to a few spawning areas, but units can get correct paths from anywhere on the map. This is very useful because in some cases units might need to repath in the middle of the map (e.g when you place a new tower somewhere).
Also, the docs mention some things about 65K overflow, that is not relevant anymore as everything is stored in the path object now (uses slightly more memory, but it much easier to use and much less error prone. For a TD game I don’t think it would be any problem at all).
This path type does require the pro version of the A* pathfinding project. If you do not have it, I could help you with an alternative solution which calculates one path per spawning area as you suggested.

I unfortunately don’t have the pro version of your project :confused: ( I try to make my game 0$ budget - Blender, Unity Indie, and the free version of your wonderful plugin :wink: )
I already have a gameobject with Aipath that calculates a decent path - my problem is making other gameobjects follow that path without creating their own path. Just a “follow that gameobject’s path” script - Although i do no know how to do this, and this is why i’m here :slight_smile:
I’m very interested in the solutions you can offer me , thanks already for your answer and your time :wink:

Lyann66 said : if your tower defense is a maze ( tower can be spawn anywhere ), this couldn't work. Imagine that you spawn a tower on a cell located at the middle of your C Path, but some ennemies were following this path, and futhermore, some ennemies are on first part of C Path and some are right behin your new spawned tower ...

A new C path should be recalculated for a group of ennemies but not for the others …


I wasn’t clear on some points, sorry about that. In my tower defense, there is a building and a combat phase (like many other TD games ) . You can only buid during build phase , and the only thing that could make a change to the path is the destruction of a tower - it may create a shorter path , and make some mobs to change path, and maybe make some mobs take a longer route, because they were far from the new path or something - that is something that can advantage the player, but is an event that cannot be performed by the user - he won’t be able to abuse that thing to make ennemies take weird routes.
Thanks for your answer :wink:

If you simply want to make enemies follow another path, you can do something like this:
`
//Script 1
Path p;
public void Start () {
p = seeker.StartPath (…);
}

public void Spawn () {
//Just make sure the path is completely calculated before spawning
AstarPath.active.WaitForPath §;

GameObject ob = Instantiate (...);
AIPath ai = ob.GetComponent<AIPath>();
//Prevent it from searching by itself.
ai.canSearch = false;
//Fake that it has calculated a path
ai.OnPathComplete (p);

}`
The above code was written directly in the browser. I haven’t tested it, but I think it would work.

Thank you very much . I will test this code as soon as possible .
If I ever finish this game , i’ll send you a copy :wink:
Keep up the pathfinding project, you make the life easier for thousands of people :slight_smile:
Cheers
Lithium

:smiley: