Skip to content

NewbySlime/pathfinding-demo

Repository files navigation

Pathfinding Demo (Random Learning Project)

This is my attempt to create a Pathfinding solution from scratch in a 2D space using Godot. After watching a GDC 2018 session, precisely "AI Summit: 'Death Stranding': An AI Postmortem" session, which motivates me to try recreating the algorithms used.

Showcased Image

NOTE: This demo is not perfect in any way, as this is a part of my learning journey.

Why Reinventing The Wheel?

I like to recreate something that I recently study about Dynamic Navmesh creation and Pathfinding from scratch. This is one of my way to learn thoroughly about something. In the end, I will not use this algorithm as there will be more stable implementation of the algorithm, but for the purpose of learning, I tried to recreate it.

Algorithm Used

  • For Navigation Mesh creation, it uses a combination of grid array of circle bodies, and Marching Squares to create the polygons based on the same grid.
  • As a note, since polygons created by Marching Squares has too many lines, it uses Visvalingam–Whyatt algorithm.
  • Then, for the triangle (Pathfinding nodes) creation it uses Greedy based ear clipping method.
  • Pathfinding method is A*, and the results are passed to Funnel algorithm to create more simplified path.
  • And since the path created by A* is not yet optimal (due to the nature of triangle shaped nodes), the resulting path will be processed again using Divide and Conquer with raycast (explained further in one of the comments of the article "Simple Stupid Funnel Algorithm " in references).

Application Usage

Use Mouse Right to move the camera by dragging, use scroll wheel to zoom in and out.

Switch mode to "Polygon Creation", "Move Polygon" or "Delete Polygon" to manipulate the Navmesh data by using polygons.

Polygon Modifying

Use "Navigate Nodes" to try navigate between start position and finish position.

Navigation Demo

Debug Step Popup will help visualize what is currently happening with the algorithm used.

Debug Visualizer

Building

While in the root directory, run Sconstruct to compile.

scons

Open Godot Engine and load this project (or import godot-workspace/project.godot file from Project Manager window). Run the main scene (navmesh_server_test.tscn) or press F5.

Optimized Build

To create much more optimized build, you have to compile the template builds of Godot Engine. Refer to build-profile/custom-template.py comments to start.

References

About

A* Pathfinding demonstration program, created as a learning journey.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages