A* Pathfinding Project

How to add a new path to another path?


#1

Hi!

I’m doing realtime strategy game,
and need to add move command through shift + right mouse click

Right now I’m doing it with creating new path after ending first one,
via own command list, shift+click adding a command that creates new path.
but it gives me endpoint animation, like he is stoping and starting all the time )

How can I create new path and merging it with first one mb?
and if I add an endpoint will it create points in between ?

Please help


#2

Adding new clicked points I guess is very bad solution )
Need to add a lot of recalculated points from some new path,
trying to use Seeker StartPath mb

need a tip )


#3

I feel like I’m doing trash

Pathfinding.Path pathCurrent = a_Entities[i].Seeker.GetCurrentPath();
Pathfinding.Path pathNew = a_Entities[i].Seeker.StartPath(a_Entities[i].Agent.destination, unitCommandExecuteParams.destinationPoint);
pathCurrent.vectorPath.AddRange(pathNew.vectorPath);

and talking to myself


#4

how to generate a new path without assigned to the agent ?
Why this one ABPath.Construct(AIPath.destination, newDestination, OnPathComplite);
never starts OnPathComplite?

Just need to build 2 paths, then combine and after that start it as one.
Is it posible ? Are they could be calculated without starting?


#5

I’ve got something like that in the end.

How can it be done better? or it is the best way?

        private Path pathCurrent;
        private Path pathNew;


        public void AddPath(Vector3 newDestination)
        {
            if (AIPath.hasPath)
            {
                if (newDestination != Vector3.zero)
                {

                    pathCurrent = Seeker.GetCurrentPath();
                    pathNew = ABPath.Construct(pathCurrent.vectorPath.GetLast(), newDestination, OnPathComplite);
                    AstarPath.StartPath(pathNew);
                }
            }
            else {
                pathCurrent = ABPath.Construct(AIPath.position, newDestination, null);
                Seeker.StartPath(pathCurrent);
            }

        }

        void OnPathComplite(Path p)
        {
            if (p.error)
            {
                Debug.LogWarning("ABPath p.error - " + p.errorLog);
            }
            else
            {
                pathCurrent.vectorPath.AddRange(p.vectorPath);
            }
        }


#6

Hi

Sorry for the late answer. I have been traveling and have not been able to answer support requests for some time.

Here’s an example of how you can combine paths: https://arongranberg.com/astar/docs/abpath.html#FakePath

However I think it’s better to not combine paths and instead adjust the slowdown distance for the agent. For example for the AIPath script there is a variable called Slowdown Distance. If you set this to zero the agent will barely slow down. You should also set “When Close To Destination” to “Continue To Exact Destination” instead of “Stop”.
You can take a look at the Patrol script which makes the agent pass through a series of points.