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
Alright then
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
Hey there. I’m glad you like it
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
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
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.
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
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?
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.
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.
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.