A* Pathfinding - Unity C#


With this project, I wanted to create pathfinding that is easily useable with an AI and to minimalize the amount of code needed to make an object move from place to place.
​
Now instead of having an entire movement section in the AI, I only have to set a destination and another script will do all the movement automatically.
​
In the next sections, I will explain more about the pathfinding.
This is A* Pathfinding with collision detection and added agent that can automatically navigate the path it's given. This makes the pathfinding easy to use.
​
The green shows the total grid.
The red shows which areas of the grid are not walkable.
The blue shows the path that is calculated and given to the agent to move over.


This is the Pathfinding Handler.
This script is what you would put in the scene itself, with the given values it will automatically make a grid which will show on screen if the debug options are set to true.
With the handler, you can get the path in world positions and
it will return the path in a Vector3 list, this way you can easily show the path or make a custom controller that moves through the positions.
​
It is also possible to offset the grid.


This is the Agent.
​
This is the script you would put on your moveable character or player,
if you want to move the object, you can set the destination where it needs to go.
From there it will calculate and get the path automatically, and also move to the given point with a set move speed.
You can also check if the agent has reached its destination.
​
Click here to see the GitHub repository & code.
​