A* Pathfinding
A tool that has the ability to make paths for A.I to follow based on a grid of tiles. It makes the shortest path possible and avoids obstacles.
Look at my code
GitHub
How it works.
At the start it makes a grid of grid tiles based on the settings you put in beforehand.
With these settings you can change the size of the grid and the size of the grid tiles. You can also change the layers that count a obstacles.
After it made a grid each grid tile checks if it has an object on it, if this object is on the layer that is set in the settings
the tile marks down that it has an obstacle on it and gets ignored by the pathfinding.
After this an A.I can send a massage with it's own transform and the targets transform with it. It then starts looking for the
target starting at the start tile. It adds 3 tiles that are closest to the target and around the tile itself to a list called TilesToCheck,
it also adds the previous tile to the tile that got added to the list. Then it checks if one of the tiles has the target on top of it.
If it does not have the target on it then it adds the 3 tiles that are closest to the target to the list and the previous step happens again,
this repeats until the target is found.
If the target is on the tile it adds itself to a different list called path, it then goes to the previous tile and adds that one to the list,
it does this until it's back to the start tile. After this it sends the transforms of all the tile in the path list back to the A.I in a reversed
order into a waypoint list.
It makes this path every amount of time that is set in the AI script.
The A.I then goes to the 1st waypoint until it is within a certain distance of it. If it is then it moves
on to the 2nd waypoint all the way to the last waypoint.
Back