
Welcome to Pathfinding in Unity!
Before you begin this course, please review the prerequisites. This course is intended for Intermediate Unity developers with experience in C# scripting.
Here let's review the naming conventions that we use for the included Unity project.
Let's review the basics of pathfinding. Graphs are a set of interconnected nodes, which are joined by edges. We will apply this data structure to a physical map, allowing us to solve for a path through a maze.
Each graph is made of nodes. Let's define a class for our most basic object, the Node.
In this lesson, we define a MapData class, designed to read the level data into the Graph.
We will create a Graph class to manage the various nodes which will comprise our level.
Our nodes will be connected by proximity. In this lesson, we define a set of compass directions and establish how nodes and their neighbors are connected.
Let's use the MVC (Model View Controller) design pattern to create some new components. We will make an interface class called the NodeView specifically designed for displaying a Node onscreen.
Let's create another user interface class, the GraphView, for managing all of our NodeViews.
In this lesson, we review creating level data as a Text Asset, allowing us to store our map as a simple set of ASCII characters on disk.
In this lesson, we create the MakeMap method in the MapData class, allowing us to read the 1's and 0's from our ASCII Text Asset. Now we have a much easier means of generating our level maps!
We can use the Resources command to help organize our project folders. Setting up the default Resources folder allows us to look for map data without needing to browse for files explicitly in the Inspector!
If using a text editor to create your level map is too cumbersome, let's use our favorite image editor to create a level! Using a one-pixel brush we can save our maze in a super small image file. This is a super interactive way to create new levels!
We have a minor bug in our MapData class. Let's examine how Script Execution Order can affect the behavior of our components and apply a simple fix.
Create and initialize a Pathfinder class in Unity, connect the graph, start and goal nodes, and visualize the search with color-coded frontier, explored, and path nodes.
Use the pathfinder to explore the graph with a frontier queue, turning visited nodes gray and frontier nodes magenta, while initializing isComplete and iterations and using show colors.
Perform a stepwise frontier-based search in Unity by expanding the frontier one node at a time, enqueueing new neighbors, and tracing a breadcrumb trail to visualize explored nodes.
Show a breadcrumb trail by rendering arrows from each node to the previous one, oriented using vector3 difference and quaternion look rotation.
Explore breadth-first search in Unity by testing on larger mazes, tuning visualization options, and measuring performance with early exit and diagnostic logs.
Learn how Dijkstra's algorithm enhances pathfinding in Unity as an improved breadth first search that tracks distance from the start, updates the previous node for the shortest route.
Toggle between breadth-first search and Dijkstra's algorithm to expand frontiers in a Unity pathfinding scene. Track distance traveled to compare path length and routing.
Learn how to enhance Unity pathfinding with a priority queue by using distance traveled as the priority, sorting frontier nodes by shortest path to reach solutions faster.
Implement a generic priority queue in Unity using a min binary heap to efficiently manage nodes by priority, with enqueue and dequeue operations that maintain heap order.
Implement a binary-heap priority queue in Unity to dequeue the top item, reheapify after removal, and expose peak, contains, to-list, and count, while exploring Dykstra and BFS in pathfinding.
In this lesson, we tweak our Pathfinder search routine to implement A* search!
A small correction to the graph search. Oops!
In this case study, we show you a simple example of how you might use pathfinding in your Unity application.
Here we show a clone of Monument Valley. The click-to-move controller relies on a pathfinder to decide how the player can reach a certain part of the level.
Check out the link in the Resources to the published article.
This course was made with the help of many online resources. Check them out here.
Check out these other great courses from GameAcademy.school!
Description
This course is designed for intermediate users of Unity (see the Prerequisites for specific topics you should be familiar with before joining).
Though Unity comes pre-packaged with an excellent pathfinding system, we explore beyond using a black box to calculate paths through your game levels.
Pathfinding and search algorithms are a core component of game development. If you want to level up your skills, enroll today and dive into implementing your own version of A* search!
Through a carefully crafted set of lectures we learn search algorithms, starting with Breadth-First Search, diving in Dijkstra's algorithm and culminating with the industry-standard A* search for pathfinding.
All concepts are presented with easy-to-understand visuals!
Some other bonus features of those course: