Poly|Nav: Pathfinding for Unity2D

1499303--84247--$polynav.jpg

Hello people,

I wanted to make an easy to use 2D pathfinding system for the Adventure Game Framework I am working on as to define walkable and non-walkable areas. Working more on that part, made up for Poly|Nav…

Poly|Nav is a polygonal based 2D pathfinding solution using A*, that is extremely easy to setup and use!
You just define walkable and obstacle polygons easily, add the provided agent component and it’s ready.
The map can dynamicaly update and the API is very similar to unity’s NavMeshAgent. You just need to call SetDestination(position) and the agent will pathfind it’s way.

It is made and ment to be used with Unity’s new 4.3 2D system

Here are two demonstration videos.

Asset Store

Documentation

2 Likes

Alright then :slight_smile:
PolyNav is live on the Asset Store. With this chance I’ve made a new video showcasing PolyNav for adventure games usage! Updated the initial post above with the video.
I might do an isometric example as well
Have fun

nice work’s !

Hey thanks :slight_smile:

Is there anyone interested in PolyNav though would like a C# version?

1 Like

I’d say its more that you should have a C# version! 68% of Unity users are C# users!

Hello!
Sorry for my English.

Yesterday I bought your component. Nice stuff!
But I have some questions.

  1. Offset from edges.

  2. Agents don’t avoidance each other like in 3d NavAgent.

Any simple built-in ways? Do you planning something of that in nearest future?

Hey there. I’m glad you like it :slight_smile:
Yes agent radius (offset from edges) is in my next to do and will be available on the next update. I didn’t have plans for avoidance between one another, but I will look into it right after the agent radious.
I hope it be done soon. Please hang on :slight_smile:

Nice!!
I’ve also been experimenting a bit with the navigation’s code, if I’ve got something interesting - I can share with you :slight_smile:

PolyNav is now available is C# :slight_smile:

The next immediate feature which I will submit tomorrow is agent offset as suggested by NilConstanin above.
If you already have done work with PolyNav, the JS version is also included, since due to the port the previous scripts will no longer work.
Enjoy :slight_smile:

@NilConstanin Im glad to hear that. Thanks

1 Like

Hey, really like the look of this and tempted to purchase it, few quick questions though.

with the “ClickToMove” script does it work with mobile touches?

thanks.

Hey,
I’m wondering if you’re planning on making it possible to make automatic obstacles? Also, make new ones at runtime?
I recently started with Unity, and for my first real project I’m working on a RTS/Tower Defense sort of a game, and I need to make new obstacles when a structure is placed.

Thanks,

  • Andrew

Edit: Is there a way to make polynav ignore colliders from other objects? I have a grid made up of quads, I need colliders on them for a ray. Currently my character can’t move into the grid-area, because of the colliders.

Hello and thanks,

The ClickToMove script included is an extremely simple example. It’s actually this:

using UnityEngine;

//example
[RequireComponent(typeof(PolyNavAgent))]
public class ClickToMove : MonoBehaviour{
	
	private PolyNavAgent _agent;

	public PolyNavAgent agent{
		get
		{
			if (!_agent)
				_agent = GetComponent(typeof(PolyNavAgent)) as PolyNavAgent;
			return _agent;			
		}
	}

	private void Update () {

		if (Input.GetMouseButtonDown(0))
			agent.SetDestination(Camera.main.ScreenToWorldPoint(Input.mousePosition));
	}

	//Message from Agent
	private void OnDestinationReached(){

		//do something here...
	}

	//Message from Agent
	private void OnDestinationInvalid(){

		//do something here...
	}
}

So all you will have to do is to replace the ’ if (Input.GetMouseButtonDown(0)) ’ with the respective Input.GetTouch functions. All you have to do is call SetDestination on the PolyNavAgent Component specifying the target position.

I hope it helps. I can provide a full script if you like :slight_smile:

Hey there,

It is possible to create obstacles at runtime. Any game object with the PolyNavObstacle Component attached is automaticaly treated. So for example if you spawn such a gameobject at runtime, the navigation map will change and update automaticaly. The same will happen when you destroy, disable or move/rotate/scale such an obstacle. Is that what you mean? :slight_smile:

Yes, there is a way to make PolyNav ignore other colliders although I must admit, its not very obvious so I will fix it in the next update.
For now, all you have to do is to move the game objects with colliders you want to ignore in the z axis to be greater than that of the main PolyNav2D gameobject.
In short, just put their Z value greater than 10 and thats it. :slight_smile:

Hey,
Ah! Didn’t see that one, Thanks a bunch! :smile:

Haha, a bit random, but it works, so thanks :smile:

Edit: Hey again,
Apparently if the object with the ‘agent’ script “can’t see its path”, it won’t move? It’s only happening with my sprites that use “PolyNavObstacle”, though.
Video: http://youtu.be/VRWjUwDNogY

Hey,
I can’t seem to reproduce the issue. What is your setup of the wall objects? Can you please post a screen shot of one of those?
Do they have the PolyNavObstacle and and if they do please check that they are in the correct layer which they should be automaticaly be added if you have selected a layer in the PolyNav2D.

1543994--90007--$pathfinding.gif

I have purchased these assets, but there are some problems with Dinamic Layer, how the script? Thanks. :smile:

1:00 and 1:02 http://www.youtube.com/watch?v=k8RH1jFYHEA

Hello,
Can you please specify what you mean by Dynamic Layer?

Hey,
Through quite a lot of testing, I finally found the problem.
If you add a “PolyNavObstacle” script to an object which already has a shape, it will act like in the video in my post.
I tried removing the spriterenderer, it didn’t work. But if I create an empty sprite (GameObject->Create Other->Sprite), and add a PolyNavObstacle, it works as intended, BECAUSE it has no sprite attached to it, therefore no shape.

Sorry if that wasn’t clear enough, tried my best =[
Anyways, do you have to use polygoncolliders? Why can’t you just use any collider?
Collider2D collider; if(collider == null) collider = GetComponent(); //in PolyNavObstacle.cs

Another thing; in C# the default access modifier is private, so you don’t have to type private. however, you do have to type public! That means you have to add ‘public’ before the “invertPolygon” variable in polynavobstacle.

Hopefully you find a fix for this, I’ll try to look a bit, but I have other things to do.
Thanks for the support,

  • Andrew

Edit: nevermind the attachment… Don’t know how to delete it.

1544990--90118--$69a09b979abbfa5860fbc637dff13e74.png

a little extra if you have a build time error to android :slight_smile:

just add # if UNITY_EDITOR and # endif code.

on PolyNav2D.cs:

# if UNITY_EDITOR
using UnityEditor;
# endif

and

# if UNITY_EDITOR
[MenuItem ("GameObject / Create Other/PolyNav2D")]
static void CreatePolyNav () {
if (FindObjectOfType (typeof (PolyNav2D)) == null) {
PolyNav2D newNav = new GameObject ("@ PolyNav2D"). AddComponent <PolyNav2D> ();
Selection.activeObject = newNav;
}
}
# endif

hopefully help.

like that in the video demo, detect if the character behind the obstacle then changed his oreder layer behind the layer obstacle, and vice versa.

1545353--90184--$1.PNG
1545353--90183--$2.PNG

thanks. :slight_smile: