# Basic Node Based Pathfinding

I am new to pathfinding but i have read and watched through some articles, blogs and videos about Pathfinding.

Since those that i have read and watched from are mainly for RTS Games, Grid Based Pathfinding.

I couldnt find any tutorials where it explains in details of how you can make your own Node Based Pathfinding System.

So i hope, you guys could give me some insightful information to enlight me or even provide useful links which can help me.

I just want to make a very Basic Node Based Pathfinding system, and from that i hope to work from it to make it into a Pathfinding System suitable for my game.

• If you're using Unity as tagged in your question, why not just use Unity's built-in Navmesh and NavmeshAgent features? Do you need specific behaviour that these don't support out of the box? Feb 17, 2015 at 14:09
• Check out Eric Lippert's great tutorial on implementing A-star in C# here: blogs.msdn.com/b/ericlippert/archive/2007/10.aspx. I have adapted it to a hexagonal terrain-grid, and pumped up performance, at this open-source site: hexgridutilities.codeplex.com Feb 17, 2015 at 23:01
• Here you can find my A* pathfinding coding tutorial, no packages. youtu.be/P7sFfFLH4iM You can use it either for grid based or node based movements. I hope it will clarify. Jun 6, 2022 at 18:55

Many moons ago when I first dabbled in pathfinding algorithms I used the following site to help me to first understand the basic fundamentals of how a simple pathfinder is meant to work, and what it's trying to achieve. Here is an example for A*.

The A* algorithm is quite popular and suitable for most pathfinding needs in gaming. A* will efficiently navigate just about any node graph when provided with a suitable rule set for finding neighbours for each node.

The question you need to ask yourself is whether or not you actually want to implement your own pathfinder from scratch; or do you instead actually want to create a game. If you're actually leaning towards the latter then there is no point reinventing the wheel and you should instead just cannibalize an existing C# pathfinder for Unity, or just use the inbuilt Unity Pathfinder which should be sufficient and easy to use for most Unity games.

Additionally this Unity plugin is also quite popular and very easy to use.

Pathfinding is a fairly complex and can be quite a deep rabbit-hole. It'll be very time consuming for you to learn, create, fix, refine and then optimize your own pathfinder - especially when others have already spent the time doing the above tasks at length(and probably doing a much better job than you! :) )

Anyway, the whole point of Unity in my opinion is to help you to bypass the need to develop your own game engine and having to write your own systems from scratch. It's done all that work so that you can just jump straight into developing games.

Here is my unity path finding using waypoints (nodes linked each others), recursion and linq: ...

using System.Collections;
using System.Collections.Generic;
using System.Linq;


...

public List<Waypoint> aStar( Waypoint goal,Waypoint nx, List<Waypoint> visited){
if( visited.Contains(nx)){
return null;
} else {
if (nx==goal){
List<Waypoint> TmpL = new List<Waypoint>();
return TmpL;
}
else {
//I use LINQ
var tmp =  nx.reachs
.Where (c => !visited.Contains(c) )
.OrderBy(t => {
return (t.transform.position-goal.transform.position).sqrMagnitude;
}).ToList();
if (tmp != null){
foreach (Waypoint ww in tmp){
List<Waypoint> TmpR =  new List<Waypoint>();
TmpR=aStar(goal,ww, visited);
if (TmpR!= null) {
return TmpR;
}
}
}
return null;
}
}
}