• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A very simple 2d tile-based pathfinding for unity, with penalty supported

Unity-2d-pathfinding

A very simple 2d tile-based pathfinding for unity, with tiles price supported.

NEW REPO

I moved this script to a dedicated repo for Unity utilities.

A newer version can be found here along with other useful Unity scripts.

This repo will remain online but won't be maintained.

About

This code is mostly based on the code from this tutorial, with the following modifications:

  • Removed all rendering and debug components.
  • Converted it into a script-only solution, that relay on grid input via code.
  • Separated into files, some docs.
  • A more simple straight-forward API.
  • Added support in tiles price, eg tiles that cost more to walk on.

But overall most of the credit belongs to Sebastian Lague, so show him your love.

How to use

First, copy the folder 'PathFinding' to anywhere you want your asset scripts folder. Once you have it use pathfinding like this:

// create the tiles map
float[,] tilesmap = new float[width, height];
// set values here....
// every float in the array represent the cost of passing the tile at that position.
// use 0.0f for blocking tiles.

// create a grid
PathFind.Grid grid = new PathFind.Grid(width, height, tilesmap);

// create source and target points
PathFind.Point _from = new PathFind.Point(1, 1);
PathFind.Point _to = new PathFind.Point(10, 10);

// get path
// path will either be a list of Points (x, y), or an empty list if no path is found.
List<PathFind.Point> path = PathFind.Pathfinding.FindPath(grid, _from, _to);

If you don't care about price of tiles (eg tiles can only be walkable or blocking), you can also pass a 2d array of booleans when creating the grid:

// create the tiles map
bool[,] tilesmap = new bool[width, height];
// set values here....
// true = walkable, false = blocking

// create a grid
PathFind.Grid grid = new PathFind.Grid(width, height, tilesmap);

// rest is the same..

More Repositories

1

RPGUI

Lightweight framework for old-school RPG GUI in web!
JavaScript
670
star
2

GeonBit.UI

UI system for MonoGame projects.
C#
399
star
3

UnityUtils

Misc collection of Unity utilities and useful scripts, some I wrote, some I found.
C#
331
star
4

partykals

Particles system library for THREE.js
JavaScript
134
star
5

SSCD.js

Super Simple Collision Detection for JavaScript games!
JavaScript
90
star
6

GeonBit

ECS-based Game Engine powered by MonoGame for C# games.
C#
64
star
7

adder

Executing untrusted code with ease.
JavaScript
47
star
8

3D-Box-Shot-Maker

Free tool to generate 3D box shots for your online products.
HTML
36
star
9

MonoGame-SceneGraph

Nodes, Culling & Entities for basic Scene Graphs in MonoGame.
C#
34
star
10

ExpiredStorage

Micro JS lib that provide local & session storage with expiration time.
JavaScript
33
star
11

ness-engine

NessEngine is a 2D rendering engine for games
C
32
star
12

Shaku

A simple yet effective web game development framework *that knows its place*!
JavaScript
23
star
13

BonEngine

A simple and fun SDL-based game engine.
C++
16
star
14

BonEngineSharp

A simple and fun SDL-based game engine in C#.
C#
16
star
15

PintarJS

Micro JS lib for direct WebGL and canvas rendering.
JavaScript
15
star
16

dcm_pool

Dynamic, Contiguous-Memory Objects Pool
C++
13
star
17

MonoSkelly

Skeleton-based animation system for MonoGame.
C#
13
star
18

spritenator

An easy way to turn dom elements into animated sprites using spritesheets!
HTML
12
star
19

sini

Simple ini files for C# with built-in config to instance functionality.
C#
12
star
20

EzSockets

Easy TCP sockets with framing for C#
C#
11
star
21

grepfunc

Simple grep-like function for Python.
Python
9
star
22

MonoGame.StaticBatch

Helper class to batch together static sprites and boost performance
C#
8
star
23

Serverito

Http framework for C# web apps.
C#
8
star
24

Vector2js

Simple 2D Vectors for JS.
JavaScript
7
star
25

SimpleOrbitControls

A simple alternative to THREE.js OrbitControls class.
JavaScript
7
star
26

MonoGame-Sprites

Simple Sprites & bone-like Transformations for MonoGame projects.
C#
7
star
27

html_validator

Offline HTML validator for Python, based on the standard v.Nu
Python
6
star
28

GeonBit.Demos

Demo projects for GeonBit engine.
HLSL
5
star
29

stinput

State-based mouse and keyboard input for JavaScript
JavaScript
5
star
30

Ogre-New-MOC

A redesign of the Ogre MOC lib (Minimal Ogre Collision) with performance boost
C++
2
star
31

NessUtils

Misc C# Utilities I often use in different projects.
C#
1
star
32

Pixelator-App

The github pages for the Pixelator project.
HTML
1
star
33

MonoGame.EasyInput

Extended mouse and keyboard input for MonoGame
C#
1
star
34

Mirrors

Micro C# lib for easier reflection.
C#
1
star
35

BucketAlerts

C++ Library for Token-Buckets based alerts.
C++
1
star
36

V8Extended

Implements fs, console, path and timers in V8 engine!
C#
1
star
37

BinaryBufferSerializer

A declarative binary serializer for NodeJS and browsers.
JavaScript
1
star
38

Nuzzles

Free puzzle games for kids - no ads!
JavaScript
1
star
39

UrlDict

Simple parser for URL get & hash params.
JavaScript
1
star
40

mongore

Creating native JavaScript classes with MongoDB backend
JavaScript
1
star
41

ShackDB

ShackDB is a lean & mean key-value database.
HTML
1
star