All Projects → coryleeio → Gridpath

coryleeio / Gridpath

Licence: mit
Gridpath is a MIT licensed multithreaded 2D implementation of A*

Projects that are alternatives of or similar to Gridpath

igvc-software
The code base for the RoboNav team's IGVC robot.
Stars: ✭ 78 (+151.61%)
Mutual labels:  pathfinding
Graphhopper
Open source routing engine for OpenStreetMap. Use it as Java library or standalone web server.
Stars: ✭ 3,457 (+11051.61%)
Mutual labels:  pathfinding
Jumper
Fast, lightweight and easy-to-use pathfinding library for grid-based games
Stars: ✭ 540 (+1641.94%)
Mutual labels:  pathfinding
unity-pathfinding
Find paths in Unity Tilemaps with A* Search
Stars: ✭ 70 (+125.81%)
Mutual labels:  pathfinding
Unity Script Collection
A maintained collection of useful & free unity scripts / library's / plugins and extensions
Stars: ✭ 3,640 (+11641.94%)
Mutual labels:  pathfinding
Pathfinding
Pathfinding library for rust
Stars: ✭ 324 (+945.16%)
Mutual labels:  pathfinding
tdme2
TDME2 - ThreeDeeMiniEngine2 is a lightweight, multi-platform 3D engine including tools suited for 3D game/application development using C++
Stars: ✭ 86 (+177.42%)
Mutual labels:  pathfinding
Goapframework
C++ General Purpose Goal Oriented Action Planning framework for Unreal Engine
Stars: ✭ 17 (-45.16%)
Mutual labels:  pathfinding
Algorithms Visualiser
Algorithms Visualiser is an opensource project made using ReactJS. Visualise Algorithms on Sorting, Pathfinding, Searching, Word Search, Backtracking.
Stars: ✭ 290 (+835.48%)
Mutual labels:  pathfinding
Libtcod
The official repository for libtcod. A roguelike development library.
Stars: ✭ 487 (+1470.97%)
Mutual labels:  pathfinding
CLF reactive planning system
This package provides a CLF-based reactive planning system, described in paper: Efficient Anytime CLF Reactive Planning System for a Bipedal Robot on Undulating Terrain. The reactive planning system consists of a 5-Hz planning thread to guide a robot to a distant goal and a 300-Hz Control-Lyapunov-Function-based (CLF-based) reactive thread to co…
Stars: ✭ 21 (-32.26%)
Mutual labels:  pathfinding
Python Tcod
A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
Stars: ✭ 269 (+767.74%)
Mutual labels:  pathfinding
Navmeshplus
Unity NavMesh 2D Pathfinding
Stars: ✭ 347 (+1019.35%)
Mutual labels:  pathfinding
unity-dijkstras-pathfinding
Dijkstra's Pathfinding Algorithm Unity Implementation. (Not being maintained by me, it is just an experiment.)
Stars: ✭ 80 (+158.06%)
Mutual labels:  pathfinding
High Speed Priority Queue For C Sharp
A C# priority queue optimized for pathfinding applications
Stars: ✭ 777 (+2406.45%)
Mutual labels:  pathfinding
Offroad-routing-engine
Off-road Navigation System
Stars: ✭ 16 (-48.39%)
Mutual labels:  pathfinding
Roguesharp
A .NET Standard class library providing map generation, path-finding, and field-of-view utilities frequently used in roguelikes or 2D tile based games. Inspired by libtcod
Stars: ✭ 316 (+919.35%)
Mutual labels:  pathfinding
Gdx Ai
Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines
Stars: ✭ 907 (+2825.81%)
Mutual labels:  pathfinding
Zeps Gui
L'interface d'un outil de calcul d'itinéraires, principalement utilisé pour se repérer dans le Netherrail de Zcraft. Nécessite https://github.com/zDevelopers/ZePS-Core .
Stars: ✭ 5 (-83.87%)
Mutual labels:  pathfinding
Lockstepengine
A lockstep solution include lots of deterministic library (Math,Collision,Navmesh,BehaviorTree,Serialization ...)
Stars: ✭ 376 (+1112.9%)
Mutual labels:  pathfinding

Gridpath

Gridpath is a MIT licensed multithreaded 2D implementation of A* aimed at 2D games with just an X,Y axis in Unity3D. It is meant to be small, simple enough that you could modify yourself, and 2D centric. It is reasonably fast and not a ton of code. It also includes a visual debugger and an example scene containing most of the math needed to setup an isometric scene in Unity3D.

There is a working example in the project in the Example folder: link to demo

A couple of notes about the demo

  • Set unity to 2D mode
  • Click the mouse anywhere to place the target, the seeker cubes will move toward the target at all times, if you place it somewhere they cant reach, they will stop moving until you move the target to somewhere they can reach again, you cannot place the target off the grid.
  • The coordinates of the grid in the demo and the grid correspond with the painters algorithm, in that the topmost square is 0,0, and the bottomRight most node is maxSizeX, maxSizeY.
  • It is a bit slow because it is using native culling with sprite renderers for each tile, you'd be better of drawing them manually in your game and only drawing the stuff on the screen
  • If you want to see the debug graph as shown in the picture enable it the inspector on the pathfinder component, it is also a bit of a resource hog.
  • The seekerAI repaths incesssantly for load testing, if you wanted to improve perforamnce, just lower the repath rate.

To use:

  • Add a Pathfinder component to an object in your scene

  • Access the pathfinder somewhere in the scene and configure the grid like so:

    Pathfinder.Instance.Init(20, 20, GridGraph.DiagonalOptions.DiagonalsWithoutCornerCutting, 4);

This will create a 20,20 grid with 4 threads, allowing diagonals, but not allowing the entities to cut corners. For diagonals several options are supported, they are:

  • DiagonalsWithoutCornerCutting - diagonals allowed, cutting corners is not
  • NoDiagonals - no diagonals allowed, only orthogonal movement will be attempted
  • DiagonalsWithCornerCutting - diagonals and cutting corners is allowed.

You can now calculate paths like this:

    // Create this method or one like it on your MonoBehaviour
    public void OnPathComplete(Path p)
    {
        foreach (var error in p.Errors)
        {
            Debug.LogWarning("The path had the error: " + error);
        }

        if (p.Found)
        {
            Debug.Log("Received path!");
            _path = p;
            _pathIndex = 0;
        }
        else
        {
            Debug.LogWarning("No path to that exists...");
        }
    }

Now call the pathfinder, (Start, or update or wherever)

PathFinder.Instance.StartPath(_myPosition.X, _myPosition.Y, _targetPosition.X, _targetPosition.Y, OnPathComplete);

Your method will be executed in the main unity thread whenever the path calculation is complete.

You can now iterate the path, and move your object to the path nodes as usual: First we'll declare a Move coroutine:

    IEnumerator Move()
    {
        while (true)
        {
            if (_path != null && _pathIndex < _path.Nodes.Count)
            {
                var nextNode = _path.Nodes[_pathIndex];
                _myPosition.X = nextNode.X;
                _myPosition.Y = nextNode.Y;
                _pathIndex++;
            }
            yield return new WaitForSeconds(1f);
        }
    }

Then we will Activate that in the start method of our MonoBehaviour

    void Start()
    {
        StartCoroutine(Move());
    }

Mark tiles as walkable/not walkable

Set tile at 0,0 to false:

Pathfinder.Instance.Grid.SetWalkable(0,0,false) 

Add weight to a tile

Set weight on the tile at 0,0 to 50:

Pathfinder.Instance.Grid.SetWeight(0,0,50); 

Decoupled use

If you want, you can use the pathfinder in your own threads, or with your own manager by simply creating the grid yoursef, and passing it to a pathsolver. This wont be multithreaded(unless you do it yourself), and you wont get the debugger etc, but it might be desirable in some cases, this is all that is required:

GridGraph graph = new GridGraph(20,20,GridGraph.DiagonalSetting.DiagonalsWithoutCornerCutting);
graph.SetWalkable(1,0,false);
graph.SetWalkable(1,2,false); 
graph.SetWalkable(1,3,false); 
PathSolver solver = new PathSolver();
solver.FindPath(startX, startY, endX, endY, graph);

Note on the implementation

Astute readers may not that the basic API calls bear some semblance to Aran Granberg's A* implementation this is because I wrote this project as a 2D replacment for for my game as I needed something a bit more 2D friendly, so a few of the API methods bear a bit of a semblance. Though they're quite a bit shorter and simpler under the hood. If you need a more complete solution out of the box or a 3D implmentation, you might consider checking out his project.

Special Thanks

Clint Bellanger's artice on isometic math

Patrick Lester article on A* pathfinding

Amit Pattel's reference on A*

BlueRaja Concurrent min-Priority Queue implementation

License

MIT license

Contact

email: corymichaellee at gmail.com

Twitter

My blog

Github

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].