Search Unity

Poly|Nav: Pathfinding for Unity2D

Discussion in 'Assets and Asset Store' started by nuverian, Jan 27, 2014.

  1. tosiabunio

    tosiabunio

    Joined:
    Jun 29, 2010
    Posts:
    115
    PolyNavAgent has movingDirection property which is a normalized vector of agent's movement. You could use it to decide which animation should be played.
     
  2. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello everyone. Sorry for late replies.

    The new version which is just submited fixes this issue.
    Thanks

    I will take a look at this for the next version, but to be honest it's very unlikely that it will make it, due to how PolyNav currently works. Sorry :/

    Thanks.
    The new version is submited. Unfortunately it still doesn't work with Physics2D since there were some complications I couldn't really handle yet. There are though some optimizations and of course some bug fixing.
    As for different agent sizes, like the reply above, I will take a look, but seems very unlikely :/

    Yes, this seems like a nice solution in case you are making a turn based game, or at least each agent is pathfinding at a different time. Cheers.

    The property you should use for that is the "movingDirection". The movingDirection is actualy a normalized vector of the velocity. So if the agent is moving precisly right, the movingDirection will be (1,0). But of course if it's moving not percisly right, it can be something like (0.9,0.1) (for kinda right & upwards movement). Here is a way to do it amongst the many there exist, at least for 4 directions and an idle:

    Code (CSharp):
    1.     Vector2 lastDir = Vector2.zero;
    2.  
    3.     void Update() {
    4.  
    5.         var dir = agent.movingDirection;
    6.         var x = Mathf.Round(dir.x);
    7.         var y = Mathf.Round(dir.y);
    8.  
    9.         //eliminate diagonals favoring x over y
    10.         y = Mathf.Abs(y) == Mathf.Abs(x)? 0 : y;
    11.      
    12.         dir = new Vector2(x, y);
    13.  
    14.         if (dir != lastDir){
    15.  
    16.             if (dir == Vector2.zero){
    17.                 Debug.Log("IDLE");
    18.                 //animator.Play("Idle");
    19.             }
    20.  
    21.             if (dir.x == 1){
    22.                 Debug.Log("R");
    23.                 //animator.Play("Right");
    24.             }
    25.  
    26.             if (dir.x == -1){
    27.                 Debug.Log("L");
    28.                 //animator.Play("Left");
    29.             }
    30.  
    31.             if (dir.y == 1){
    32.                 Debug.Log("U");
    33.                 //animator.Play("Up");
    34.             }
    35.  
    36.             if (dir.y == -1){
    37.                 Debug.Log("D");
    38.                 //animator.Play("Down");
    39.             }
    40.  
    41.             lastDir = dir;
    42.         }
    43.  
    44.         if (Input.GetMouseButtonDown(0)){
    45.             var goal = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    46.             if (agent.SetDestination(goal) == true){
    47.                 Debug.Log("On my way...");
    48.             } else {
    49.                 Debug.Log("Can't go there...");
    50.             }
    51.         }
    52.     }
    Again, there are many ways to do this, this is just a simple one to get you going :)
     
  3. fighder

    fighder

    Joined:
    Feb 1, 2015
    Posts:
    17
    Hey, I was loving the plug in until I actual used it in my game. For some reason my enemies are not moving:


    using UnityEngine;
    using System.Collections.Generic;

    //example
    [RequireComponent(typeof(PolyNavAgent))]
    public class getPlayer : MonoBehaviour
    {


    public Transform player;
    private PolyNavAgent _agent;

    public PolyNavAgent agent {
    get {
    if (!_agent)
    _agent = GetComponent<PolyNavAgent> ();
    return _agent;
    }
    }

    void Update ()
    {

    Vector2 playerPos = new Vector2 (player.position.x, player.position.y);
    agent.SetDestination (playerPos);

    }

    }

    I literally copied the click to move script and adjusted it a bit. The only way to get this working is if I start move the player first.
     
  4. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    @fighder
    Could it be that the requested position is (the position of the player) is blocked? You can do a quick test like this:
    Code (CSharp):
    1. if (agent.SetDestination(playerPos)){
    2.     Debug.Log("Goal is not blocked")
    3. }
    Let me know
     
  5. conker87

    conker87

    Joined:
    Feb 8, 2015
    Posts:
    1
    Is this script any good for a side scrolling 2d platformer? I've been searching and searching for system that can integrate with Ferr2D to no avail. Literally the only thing that's stopping me from progressing.
     
  6. Lethil

    Lethil

    Joined:
    Feb 1, 2012
    Posts:
    3
    Hello! Your product really intrigues me, but due to console development, I'm limited currently to using Unity 4.3. It looks as if your most recent releases require 4.6+.

    Do you support Unity 4.3 still?
     
  7. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    If you platform game is depth based (like Castle Crushers) then you can use PolyNav for that, but if you need pathfinding for a jumping platform like mario, then PolyNav can't be used for that. For these kind of games it's better to look after a node based pathfinder specific to this genre, since it requires a special setup.

    Hello,
    Yes, it still works with 4.3. It's just that the Asset store taged it with 4.6 because that's the version I used to submit it.
    Thanks :)
     
  8. Beefmaster5000

    Beefmaster5000

    Joined:
    Jan 3, 2015
    Posts:
    3
    Thanks so much!! This is excellent! However, I'm noticing an issue. I have a test bed with two NPCs. These both have 5 animator states (N,W,S,E and Idle). I'm noticing an issue using the solution you provided above (using movingDirection to change animator states to match NPC direction). Many times, when setting the same vector3 destination for both NPCs, one or both will 'shimmer' by switching back and forth from one state to another multiple times per second, causing an unwanted effect. Any tips as to how to avoid this issue when NPCs receive the same destination and arrive there at the same time?
     
  9. RichCWilliamson

    RichCWilliamson

    Joined:
    Jan 13, 2014
    Posts:
    5
    Love the product. So - I am making a board game, and love the pathfinding. Is there a way for the agent to pathfind "immediately"? I have an ai player, and the ai is not going to want to wait for the agent to navigate around the board to find the optimal path. I am considering using the activePath._items[] but I would have to translate the intended path to map up to my other game objects. If I wait for the navigator to complete its route, it definitely runs into the correct locations and generates an event but since the ai is the player, I need a way to immediately navigate the entire route...basically with no physics. Just go to the optimal point, change direction, to to the next optimal point. I have created a system of tunnels using your obstacles, then placed a square obstacle blocking each tunnel. In this way, when tunnels are open, the agent uses that route and then runs into "cities" on the way to the final destination. I tried setting mass=1, speed =500 etc...but basically if I do that it goes out of control. I've also considered using the method you have OnNavigationPointReached, but that would be a little slow for the ai turn. Thank you for the work on this - its not replaceable with any other nav product I have tried (and I tried about 7 of them from the store)....I recommend everyone buy this, now!
     
  10. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey, you are welcome :)
    Do you get constantly changing direction using the example with the 'logs'. I mean does the script constantly logs changing of directions as well? This could be one step to finding the issue :)

    Let me know.
    Cheers!

    Hey there and thanks a lot!

    While I can't exactly understand your use case, but you can try using the PolyNav.FindPath directly which returns a path and then actualy set the game object position to the last vector of the array directly. Here is an example:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4.  
    5. public class Example : MonoBehaviour{
    6.  
    7.     void SnapToPathResult(Vector2 start, Vector2 end){
    8.  
    9.         PolyNav2D.current.FindPath(start, end, OnPathResult);
    10.     }
    11.  
    12.     void OnPathResult(List<Vector2> path){
    13.  
    14.         if (path.Count == 0){
    15.             Debug.Log("No path to target exists");
    16.             //more stuff...
    17.         }
    18.  
    19.         transform.position = (Vector3)path.Last();
    20.         //Raise events and do more stuff... :)
    21.     }
    22. }
    (This doesnt even need a PolyNavAgent if you dont actually need it to navigate)
    Let me know if thats what you are looking.

    Cheers and thanks!
     
  11. RichCWilliamson

    RichCWilliamson

    Joined:
    Jan 13, 2014
    Posts:
    5
    Great ideas...I will give that a shot! Much appreciated example code!
     
  12. RichCWilliamson

    RichCWilliamson

    Joined:
    Jan 13, 2014
    Posts:
    5
    Oh - I just realized what you said - I don't need an agent!! Yes! I will just try and use the PolyNav2D.current.FindPath(start, end, OnPathResult); I thought you had to have an agent to find a path...but I will try this...the PolyNav2D has its own way of finding a path! Maybe worth creating an example code for future release. I think there is a lot of value in finding an optimal path, but then not moving an agent towards it. Or perhaps firing a missle in the perfect location, like a guided missile. Can't wait to try!
     
  13. Meetch

    Meetch

    Joined:
    Feb 13, 2015
    Posts:
    1
    Amazing tool Nuverian! Thank you so much for the constant updates and responses to questions.

    I have a simple question.
    I'm trying to have 2 separate PolyNav2D areas (2 different rooms within an isometric 2d game) that will allow the player to teleport between the two rooms when entering specific colliders for each. I'm trying transform.position to move the player character to a set location in a different room with a different PolyNav2D attached. Is what I'm trying to do possible?

    Thanks for your time and assistance!

    Regards,
    Meetch
     
  14. Beefmaster5000

    Beefmaster5000

    Joined:
    Jan 3, 2015
    Posts:
    3
    Yes, my console has a lot of spew. (ie: going west \ going east etc) I am using click to move, have 2 npc's with 5 animator states (NSEW and Idle) and when they get assigned the same destination, they seem to 'fight' over who gets to the vector 3 destination even after they arrive. It seems like they're toddling states multiple times a second once they reach their destination. Not a good situation... :(

    My code:


    using UnityEngine;
    using System.Collections.Generic;

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

    private PolyNavAgent _agent;
    public PolyNavAgent agent{
    get
    {
    if (!_agent)
    _agent = GetComponent<PolyNavAgent>();
    return _agent;
    }
    }

    private Animator anim;

    Vector2 lastDir = Vector2.zero;

    void Update() {

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

    var dir = agent.movingDirection;
    var x = Mathf.Round(dir.x);
    var y = Mathf.Round(dir.y);

    //eliminate diagonals favoring x over y
    y = Mathf.Abs(y) == Mathf.Abs(x)? 0 : y;

    dir = new Vector2(x, y);

    if (dir != lastDir){

    if (dir == Vector2.zero){
    Debug.Log("IDLE");
    anim = gameObject.GetComponent<Animator> ();
    anim.SetInteger ("state", 0);
    //animator.Play("Idle");
    }

    if (dir.y == 1){
    Debug.Log("North");
    anim = gameObject.GetComponent<Animator> ();
    anim.SetInteger ("state", 1);
    //animator.Play("Up");
    }

    if (dir.x == 1){
    //Debug.Log("East");
    anim = gameObject.GetComponent<Animator> ();
    anim.SetInteger ("state", 2);
    //animator.Play("Right");
    }

    if (dir.y == -1){
    Debug.Log("South");
    anim = gameObject.GetComponent<Animator> ();
    anim.SetInteger ("state", 3);

    }

    if (dir.x == -1){
    Debug.Log("West");
    anim = gameObject.GetComponent<Animator> ();
    anim.SetInteger ("state", 4);
    //animator.Play("Left");
    }

    lastDir = dir;
    }

    if (Input.GetMouseButtonDown(0)){
    var goal = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    if (agent.SetDestination(goal) == true){
    Debug.Log("On my way...");
    } else {
    Debug.Log("Can't go there...");
    }
    }
    }
    }
     
    Last edited: Feb 16, 2015
  15. justjim

    justjim

    Joined:
    Feb 12, 2014
    Posts:
    1
    Hey there,
    First of all , congrats for your plugin it is great!
    I am using it on a game that has a top-down view of a city and humans move around in the city.
    I wanted to ask if there is a way to have 2 different PolyNav2D spaces in the same screen. I am talking about the outer green colliders that bounds a moving space for agents. Because now I used an ugly silly solution of connecting the two spaces with a narrow path as seen on the image.


    I would appreciate any help. Thanks :)
     
  16. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    First of all great plugin.

    But as it has been mentioned before then it does not require many items and NPC's before the framerate makes the game unplayable. I can see you are working on a fix using 2DPhysics. Do you have an eta? We are to release our game on a few platforms in a few months, so if the eta is far away i better roll my own solution ;)

    Cheers BFGames.
     
  17. Hawkwise

    Hawkwise

    Joined:
    Aug 4, 2013
    Posts:
    1
    Hey,

    Was hoping someone could help me out with this. We've added PolyNav to the game we're working on currently, and it seems to be mostly working perfectly, except for one issue. When our AI follows the player, and the player goes around a PolyNavObstacle the AI reacts poorly. It slows down, grinds the corner or edge of the blocker, and generally looks like it's trying to path to the player, but not doing so well.

    Not sure what we've done wrong, it all looks correctly setup. The radius, and avoid radius is set to be the same on the AI, and the PolyNav scene settings object.

    The blue debug raycast seems to be tweaking out at the same time, when there is an obstacle between the AI and the Player it shortens to barely visible when the path is not immediately clear.

    I've seen the demo of this and they are all super smooth, just can't figure out what we've buggered up.

    Edit: I'm using the Behaviour Designer Plugin, and the Poly Nav Agent script to just have a basic "Follow" the player type AI.

    Edit 2: It seems to be somewhat fixed now. Lowering the amount of calls to update the destination seems to have fixed it.

    Any ideas?

    Thanks,
     
    Last edited: Feb 19, 2015
  18. Jalouse

    Jalouse

    Joined:
    Feb 21, 2015
    Posts:
    2
    Hi ,

    I am wondering if you can constraint movement to perpandicular path , with only vertical and horizontal lines inside the path ?

    Thanks
     
  19. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Sorry everyone for late replies!

    Hey,
    Yeah, you might don't need an PolyNavAgent at all considering the situation :)
    I could add some extra example scene demonstrating that in the next release as well.
    Cheers!

    Hello and thanks a lot!
    This is a quite requested feature, which is currently not possible to have more than one PolyNav2D script in the scece. There was a nice guy @trothmaster who made some requierd changes for this to work, but unfortunately I didnt have the time to get into acually implementing his work yet. I will take a look at this since it's obviously usefull, once I get the time (soon) :)
    Cheers!

    Hello,
    I suppose the issue is that bevause you set and integer, there exist some transitioning going on between the 2 states, which is something that since it's a sprite you don't want to have. You can either make sure that there is no transitions or use Play function on Animator (not CrossFade). Let me know if that works.
    Cheers!

    Hello and thanks!
    Like my other reply, unfortunately this is not currently possible to have more than 2 PolyNav2D components in the scene, but I will take a look at this soon enough :) So currently your way, is definetely the best way as of now :)
    Cheers!


    Hello there and thanks!
    I was encountering some difficulties implementing it using Physics2D. The weird fact is that the first version of PolyNav was working with Physics2D :) I expect to get a look at PolyNav for this feature as well as having more than one PolyNav2D component in the scene, within the next week.
    Thanks!

    Hello,
    Can you please try and lower the LookAhead distance and let me know.
    If possible at all, it would greatly help to send me a reproduction project where this issue occurs. If possible.
    Cheers and thanks!


    Hello,
    I suppose the case scenario is grid like movement?
    There is no integrated way to do that since it's not a grid pathafinder, but one solution could be to alter the Vector2[] path in a way that is snaps to a grid. Of course that does not guarantee that some of the resulting position are out of bounds in case the map is non uniform. Hacky, but it works :)

    Cheers!
     
  20. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Perfect!
     
  21. Beefmaster5000

    Beefmaster5000

    Joined:
    Jan 3, 2015
    Posts:
    3
    There's actually no transitioning. Just 4 walk cycles. No fancy stuff. I get the same results when using the play function... Surprisingly, even when I threw in a 1 second delay in the clicktomove script prior to switching animations, I still get the same effect...
     
  22. Greenwar

    Greenwar

    Joined:
    Oct 11, 2014
    Posts:
    54
    @nuverian

    Hey,

    Is there any ETA on the physics based LOS checking, etc? Is it being worked on at all, if not, will it be? Any information would make a happy camper. The asset is great as is, but unusable for some of us who needs to use quite a few obstacles.

    Maybe you could sell it as an add-on? I'd pay for it..
     
  23. Zelek

    Zelek

    Joined:
    Jun 12, 2010
    Posts:
    87
    I just wanted to chime in as one more person who would really appreciate being able to have multiple PolyNav2D instances in the scene. Hopefully we hear more about this soon!
     
  24. shadow-river

    shadow-river

    Joined:
    May 29, 2013
    Posts:
    63
    Hi, again i would like to say how awesome this package is. I have a new game on the Google play store that uses this package check it out hope you like it.

    Game link: SploshFrog
     
  25. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    this plugins is interesting, but having to define the colliders manually turns in a little nightmare on my case , i am using another asset called Destructible2D for my map , so my hero can dig tunnels and even create ground , D2D redefines colliders on the fly , i would like PolyNav to create the map based on the colliders in the scene , and update its map on my call or automatically , this would also be useful for people using Ferr2D another popular ground generation assset

    any chance this could happen?
     
  26. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello everyone.
    Sorry for being late to the update, but,
    I've just submited the new version 1.5 which basicaly is a huge performance optimization update.
    In practise, I have rewriten the whole core pathfinding algorithm and path requesting.
    Furthermore, having multilpe polygon paths in the main navigation polygon is now fixed and works fine. This can help some of you creating the map proceduraly.

    The next feature I will look at, will be support for multiple PolyNav2D maps and possible linking between them.
    Cheers!

    Hello,
    Sorry I can't really know what could be the issue but seems mostly irlevant to PolyNav. I don't have a problem if you want to send me a test project to check out though.

    Nice! Thanks for sharing with us :)

    Hello,
    You don't realy have to draw them manualy, any game object with a PolygonCollider2D and a PolyNavObstacle will register automaticaly.
    With that said, reconstructing the map every frame is realy not recomended for performance. It would be better to reconstruct it between some intervals instead.
     
    Lasseastrup3 likes this.
  27. Saputo-Studios

    Saputo-Studios

    Joined:
    Dec 8, 2012
    Posts:
    3
    Updated PolyNav and got this.

    See image
     

    Attached Files:

  28. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello everyone.

    PolyNav v1.5 is live on the asset store.
    This fixes lot of performance issues.
    There are some slight API changes. Furthermore Messages are no longer send for performance. Instead they have been replaced with c# events. Please read the documentation an take a look at the example scripts.

    Thanks

    Hello
    Please also unpack the included Playmaker.package to update the Playmaker actions as well as the NodeCanvas one if you use NC.

    Thanks
     
    OnePxl likes this.
  29. Saputo-Studios

    Saputo-Studios

    Joined:
    Dec 8, 2012
    Posts:
    3
    Your Playmaker actions are for NC, did you upload the wrong ones?
     
  30. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Oooops! Im so sorry about this!
    I have attached the correct playmaker actions package here.
     

    Attached Files:

  31. shadow-river

    shadow-river

    Joined:
    May 29, 2013
    Posts:
    63
    hi, in my scene I've got around 200 squares each square has a poly nav obstacle attached. what im trying to do is draw a path along each square you touch by disabling the poly nav obstacle script. the whole system works amazingly well except the fps drop. when ever I touch a square to disable the script it takes a hit of about 30 fps when I move the cursor along to draw a path fps drops to between 2 - 20 fps. but when im not disabling the obstacle scripts the fps is back to normal and stable, I was wondering if there was a work around for this.( it is necessary for each square to have a obstacle script attached.)

    thanks
     
  32. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,

    The reason for the FPS drop is that basicaly you are forcing a Map Regeneration each time you enable/disable a PolyNavObstacle and generating a map with 200 obstacle polygons is a bit heavy.
    With that said, after the optimization made to the actual pathfinding, I am now also working towards optimizing map regeneration as well.

    For now I unfortunately dont have any workarounds to provide you, considering the fact that you do need enabling/disabling PolyNavObstacles and their effect be realtime :/

    Hopefuly I can get the map regeneration optimization soon, but I dont want to promise when, because last time I did, I went off my promise by some days :)
     
  33. Kaemalux

    Kaemalux

    Joined:
    Aug 1, 2013
    Posts:
    45
    Hello! I had a look at your demo and your plugin seems really interesting.
    Before buying it i have a couple of question:
    - can it be used by enemies to reach player while it is moving, in a 2D topdown game?
    - in case there is an obstacle in the path that cannot be overcome, like a door that is closed, can you set the behavior or simply let him chasing/moving, or will it have problems?
    Thanks in advance, cheers!
    :)
     
  34. rileypb

    rileypb

    Joined:
    Apr 16, 2013
    Posts:
    1
    I'm definitely interested in buying PolyNav. Does it work well with Unity 5?
     
  35. hobblygobbly

    hobblygobbly

    Joined:
    Nov 13, 2013
    Posts:
    3
    I have a question before I purchase your product.

    I'm assuming that it works fine in local space? To provide an example:

    You have a ship on the ocean, the actual ship moves in world space, and it has child objects (crew members) that move around the ship itself (local space, relative to ship). If I define the polygonal walkable/obstacle as a child/local space of the ship, will the crew members move fine as well while the actual ship in world space is moving at the same time? Some other solutions don't do any local spaces that I've looked into, so I'm wondering if yours does.

    Thanks.
     
  36. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,

    Thanks for your interest in PolyNav.
    The answers to your questions are mostly based on how you are going to script your behaviours, but yes you can use it to follow the player of course :)
    In case there is an obstacle that blocks the only path, it means that there is no path and as such the enemy will not be able to go to the destination. In this case it can either stop or go as closer as it can.

    Cheers!

    Yes it works fine with Unity 5. There is only one thing that will need to be updated (can be auto updated by unity) which is BoxCollider2D.center to BoxCollider2D.offset.

    Cheers!

    Hello,

    While your request is valid and sounds simple enough, in practice it's not that simple for various reasons.
    When moving the PolyNav walkable area, currently the map does not regenerate automaticaly.
    Furthermore if you set a Vector2 destination this is always world space. So if you move the ship while a pirate is moving on the ship somewhere, the destination will naturaly remain the same and it will be in world space. A solution to that would be to update the destination per frame, at least while the ship is moving.
    Last but not least, currently there is only one PolyNav walkable area supported, so if you are after to more than 1 ship, it wont be possible. (this is the feature Im working on next by the way).

    So unfortunately what you are after currently is not supported out-of-the-box, but I can take a look at making this a possibility as it sounds nice enough to have.

    Cheers!
     
  37. Kaemalux

    Kaemalux

    Joined:
    Aug 1, 2013
    Posts:
    45
    Hi nuverian!
    Thanks for your answer!
    Just one last thing, could this be done in any kind of 2D environment? I am using mostly 2D polygon and edge colliders, is there any problem to set up a following AI in this case? Consider a simple top-down 2D game with enemies chasing player if they are in the same room or in range. Do you see any difficult on doing this?
    Thanks again, and congratulation for your answer, i am surely going to buy it, i had a look into demos and it is such good. :)
     
  38. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello again and thanks.

    Well it can work in most 2D scenarios. I mean, I can't really vouch for ALL scenarios that might come along :)
    Regarding colliders, PolyNav can read either PolygonCollider2D or BoxCollider2D for when generating the navigation area for walkable or obstacles. EdgeColliders can't be used since they do not really form a polygonal area.

    Basicaly the way this works is that you define a base walkable area with a PolygonCollider2D or BoxCollider2D, and then on each obstacle you add the PolyNavObstacle component. That same gameobject needs to have either a PolygonCollider2D or a BoxCollider2D so that it can be taken into acount when generating the map.

    Let me know if that answers you questions and if not, please let me know any clarifications.

    Best regards,
    Gavalakis Vaggelis
     
  39. MoDDiB

    MoDDiB

    Joined:
    Jun 25, 2013
    Posts:
    9
    Hello, I read that the whole source code of your pathfinding engine is available in the package and it sounds interesting,
    because I'm making a fully deterministic game engine for unity.
    Do you use unity built-in physics like raycast ?
    I want to know what I will have to rewrite if I take your asset !
     
  40. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    Yes the full source code is included. I can't possibly know what you will need to alter since I don't really know the needs :)
    No, Physics are not used at all.
     
    MoDDiB likes this.
  41. tosiabunio

    tosiabunio

    Joined:
    Jun 29, 2010
    Posts:
    115
    When exactly disabling repath is beneficial? With repath disabled my agents literally cut corners and go through obstacles which isn't preferred behavior in most cases.

    With path debug active I see proper path calculated:



    but agent instead of following it suddenly cuts corner:



    and goes beyond walkable area. Enabling repath solves the issue.
     
  42. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey,
    I dont realy get that kind of behaviour here :/
    Enabling Repath is mostly needed when the navigation map changes, otherwise it's not realy needed and you can disable it for performance.
    Not in your case this doesnt seem to work and I wonder why.
    Could it be that you have altered the code somehow?
    I am also asking because I see some kind of offset from the edges implementation (?)

    Thanks
     
  43. tosiabunio

    tosiabunio

    Joined:
    Jun 29, 2010
    Posts:
    115
    My agent settings are:



    The code hasn't been modified since you exposed Look Ahead Distance. PolyNavAgent.cs is 11559 bytes long (MD5: 30431E9D6FED3DB5108F8F4C0295145C).

    The only way to force my agents to go around cornres properly is by enabling Repath.
     
  44. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Sorry went AFK,
    I just entered the exact same settings at least in the demo scene and works as expected. I can't realy depict what could be the actual problem here.
    I can of course tell you to enable Repath if that solves your issue, but I would also certainly like to figure this out.
    I suppose you are just calling SetDestination when you click the mouse on the target destination right?
     
  45. tosiabunio

    tosiabunio

    Joined:
    Jun 29, 2010
    Posts:
    115
    Yes, SetDestination is the only interaction with agent component. Proper path is drawn, agent follows it and suddenly decides to go directly to the destination. I will try to extract a test scene for you, but this is difficult because of many dependencies I already have.
     
  46. Praesidium

    Praesidium

    Joined:
    Dec 5, 2012
    Posts:
    29
    :eek: i bought polynav2d thinking this was working somewhat like this , so it was optimized and it was too much trouble to do that myself.

    But then i draw lines in gizmos from every node to a link of that node and i get something like this :eek:

    this is the drawing in the scene, kinda ridiculous :(




    Am i forgetting any step ? this is after calling the "GenerateMap".

    If this is all the asset can do i kinda feel robbed :(

    I've noticed the actual pathfinding its pretty optimized and doesn't run through all the neighbors (even though it runs through a lot of them), but this is very troublesome in terms of map creation , which i don't even want to generate in runtime but I don't think there's a way to do it in editor (even if i call the generateMap in the editor, when i go play the nodes variable resets, and i commented the generateMap from runtime)
    Since i cant split my map by quadrants to multiple polynavs since the asset doesn't allow it, is there anyway to use it in a map with more than 700+ static obstacles (which gives 4x nodes) with this asset? preferably with a baked map instead of runtime created?
    (ps: each of those red rectangles is a box collider2d)
     
    Last edited: Mar 19, 2015
  47. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    @Praesidium

    Hello,
    No you are not forgeting any step. Sorry, I never said or promoted that the asset generates a navigation "mesh". It might do in future, but currently it does not.
    You can't generate the map in editor only, but even if it was possible, you will encounter problems with thousands of obstacles when requesting a path. I think you will be better going with a grid solution from what I can tell.
    It's a very cheap asset (30$), but if you feel robed by what it offers, please ask for a refund and I will gladly provide one.
     
  48. Ando_

    Ando_

    Joined:
    Jun 8, 2014
    Posts:
    1
    Hello i purchased PolyNav and its working great but I am creating a procedurally generated top-down game and I was wondering if it is possible to create a walk able area around my level part then save it as prefab and then when it is generated its walk able area and the other prefabs areas, since they will overlap, could combine into one whole walk able area or that the AI will act as if they are all just one area?
     
  49. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    Unfortunately this is not possible right now. The exact opposite is possible though if it helps. Which means that you can have prefab obstacles, but there can be only one PolyNav2D area in the scene at any time.
    Sorry :)
     
  50. Praesidium

    Praesidium

    Joined:
    Dec 5, 2012
    Posts:
    29
    How can i ask for a refund? can't find any button to do so, and I'm sorry i didn't find your asset helpful, i know it is for a lot of other people.