A* Pathfinding Project

Grid Graph changing path results in units doing a dance (Not finding the proper path for many seconds)


#1

Hi,

I am new to this forum, so I hope this is the right place for these questions. If I should give you more information, please let me know.

I have recently tried to convert my project that was using the Brackeys NavMesh tutorial to using the A* project and Grid Graphs.

The result can be seen in the video at the link below; When changing the destination while it is on a path, the unit will serve around for a while and eventually start heading to it’s given position.

Edit 2: link was still broken. Now it is not alone on the line.https://drive.google.com/file/d/1Rjd3vOOhHBCkLHbSJnS2YEWe34M6S7FL/view?usp=drivesdk

I am iterating through all of the units with a for loop and then setting the destination of the units like so:

public void setDestination(Vector3 destination) {
normalPather.destination = destination;
normalPather.SearchPath();
}

Where normalPather is the attached AIPath component.

The settings for the grid graph and AI path are shown in the gif and the images.


I believe that something wrong either with the settings or with the way I am setting the destinations.
Do you know why this is occurring? What changes would you recommend I make? Should I instead be using a transform as the destination?

Thanks for your help.


#2

Hey,

I can’t see anything that looks wrong right of the bat.
though a few remarks.
In your set destination function you can get rid of this SearchPath.

normalPather.SearchPath();

your AIPath is set to recalculate it’s path every 0.1 seconds


so you don’t really have to tell it to go find a path.

Second, your RotationSpeed is extremely high. 720 is definitely a large number I wonder if it overshoots the rotation.

Third your Pick Next Waypoint Dist is really small. To help you understand what it means take a look at the variable overview here: https://www.arongranberg.com/astar/documentation/dev_4_3_11_59993326/aipath.html

Though I don’t think any of these really cause the issue you’re having here.
Could you further explain what normalPather is and how it’s setup ?


#3

Thanks for the quick response.

I tried changing the variables that you mentioned, but reducing the turn rate (360, 180 and 0.5) and increasing the Next Waypoint Dist (both 1 and 2) didn’t solve the problem, but it did change the pattern of the wave a bit.

I have linked a video here: https://drive.google.com/open?id=1Z11kXa6yub8SUlh89us6kFoWTqj2P4mg

normalPather is just a local variable for the AIPath component. it is configured in Start and only referenced for setting the destination (on mouse clicks) and setting the speed (once, during the start).

normalPather = GetComponent<AIPath();

I am currently using Unity 2019.1.14f1, so I will try updating it and see if it resolves the issue.