Search Unity

Poly|Nav: Pathfinding for Unity2D

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

  1. nuverian

    nuverian

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

    Thanks for getting PolyNav!
    You don't need to import NodeCanvas nor Playmaker packages if you don't have either of them in your project. These packages are simply extensions to these assets. Please take a look at the included documentation and of course the Demo scene for your convenience. If you need any further help, just let me know.

    Thanks again,
     
  2. Zelek

    Zelek

    Joined:
    Jun 12, 2010
    Posts:
    87
    Any ETA on this? Please just let us know if you decided not to add it. It's been nearly two years now...
     
  3. syamilsynz

    syamilsynz

    Joined:
    Dec 22, 2013
    Posts:
    31
    Hello @nuverian

    I make a game with Unity UI. My agent gameobject is inside the "canvas" and working fine if I create empty gameobject that have PolyNav on it outside the "canvas". However, PolyNav seem does not work when I put it inside a "canvas" since I want to use the obstacle as a part of UI and my agent will not move.

    Did I miss something or PolyNav does not work on UI?

    I have a request, can u give more demo version as references. Thanks
     
  4. blober81

    blober81

    Joined:
    May 6, 2016
    Posts:
    97
    Does anyone know how to edit maxSpeed so I can make the object stop and go when I want ?

    When I set maxSpeed to "0" the unit stops but then when I set it back to "1" again it refuses to move. In the inspector it shows that the maxSpeed value is set to "1" so the maxSpeed does get updated however the agent doesn't move.

    In navmeshagent this worked perfectly. It would be a good thing if there was a polynav guide.

    This is my code;

    Code (csharp):
    1.  
    2.  
    3. void Update()
    4. {
    5. agent.SetDestination(GameObject.Find(DestinationName).transform.position);
    6. }
    7.  
    8.  
    9. public void stopForTarget(float amount)
    10. {
    11. agent.maxSpeed = amount;
    12. Debug.Log("speedtest "+ agent.maxSpeed);
    13. }
    14.  
     
  5. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    It's not that I decided not to do it, but rather just that I didn't have time to work in PolyNav due to the other Unity projects, and will do after summer break.
    Thanks and I am sorry for the delay of that feature.

    Hello,
    PolyNav will not work correctly under the UI. This is basically because the UI element coordinates are driven by the UI system. Even though I can take a look at this, I don't think it will be possible to support with the current way PolyNav is working. Sorry :/

    If I can help you with anything else, please let me know.
    Thanks.

    Hello,

    I just replied to your send PM regarding this issue. Let me know.
    Thanks.
     
  6. ashley

    ashley

    Joined:
    Nov 5, 2011
    Posts:
    84
    Sorry for coming back to this months later, but other things cropped up.

    I'm not entirely sure what you mean. I think the easiest way would be to try it out. Would you be willing to authorise a refund if it didn't work as I was looking for? I have the scene set up so it would just be a case of adding and playing around so I could do it within a day.

    Thanks.
     
  7. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    @ashley Hello again. No problem. I've send you a PM regarding your concerns :)
    Cheers!
     
    ashley likes this.
  8. Lodeman

    Lodeman

    Joined:
    Aug 16, 2015
    Posts:
    4
    Hi there, sorry I know this is a rather old post. But I just wanted to say thanks for this information.
    I've also implemented this in my version (seemed it still wasn't in the version I bought from the Asset store a few months ago), and it indeed works great and is nicely organised.

    My game also has an additional requirement: I have crew members walking around inside of a moving spaceship, so I've changed the scripts so that a polyNav instance can be attached to a moving gameObject. Everything is calculated relatively, and navAgents update the required positions taking into account spaceship position and rotation. It took me a good 2 days and some head-scratching, but ultimately it wasn't too bad to implement the changes once I found my way around the code (and remembered all my old algebra lessons!).

    Previously I had been just using the default polyNav, and having to re-calculate the nav mesh each frame to allow the relative movement. I was at about 40 FPS due to that. Now having implemented all the changes, I can happily report I'm back at a solid 60 FPS (which I assume is capped anyways).

    So yeah, just wanted to compliment this great product. Works out of the box, and can be customized to suit advanced needs as well!
     
    nuverian likes this.
  9. Gatau

    Gatau

    Joined:
    Feb 20, 2015
    Posts:
    9
    Hi

    I wanted to ask you about an issue I am having when the agents are chasing a moving target. As you can see on the screenshot linked below I have a few brown trolls chasing a green player, but as the player steps close to the trees which are obstacles with 0.2 extra offset on the Poly Nav Obstacle, the agents stop chasing the player. As the player steps outside the walkable area the enemies distance to the targets becomes 0 and they stop. I understand that this is how it might be supposed to work but I am wondering if there is a way for make them keep chasing the player even if he is inside the obstacles "holes". The reason for wanting this is simple: if I make the hole smaller, enough for the player to be unable to run in "outside" the walkable area, the enemies will get suck on the corners of the trees Box Collider 2D while running around them.

    I get the same problem by using the "Add New Polygon Obstacle" option.

    Screenshot: https://www.dropbox.com/s/rpe5q99g17nsd2i/nav_issue.PNG?dl=0

    I love this asset btw. It's the best 2D nav asset I've found so far.
     
    Last edited: Aug 4, 2016
  10. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey!

    Thank you very much. I am very glad you like PolyNav and that you have managed to tailor it to your needs!
    Cheers!

    Hey,

    Thanks! Glad you like PolyNav so far :)

    As far as I understand correctly, if you enable the option named "Closer Point On Invalid" on the enemies PolyNavAgent component inspector, then the enemies will continue chasing the player even while the player is within these offset areas of the obstacles.

    Please try enabling "Closer Point On Invalid" for the enemies and let me know if that works for you.
    Thanks again!
     
  11. Gatau

    Gatau

    Joined:
    Feb 20, 2015
    Posts:
    9
    That works very well, thank you! So awesome :D
     
  12. Sinheldrin

    Sinheldrin

    Joined:
    Aug 6, 2016
    Posts:
    1
    Hi,

    I am playing around with PolyNav and I got something which looks like a bug:
    When I use a box obstacle, the path finding sometimes goes through the box instead of around.
    It seems to stop working when the box is around 0,0.

    See here: http://imgur.com/a/CO0ZF
    In the first image, the obstacle is in 0.5 0 and the agent goes around.
    In the second image, the obstacle is in 0.1 0 and the agent goes through.

    I am on Unity 5.1.0f3
     
  13. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    You are very welcome :)

    Hey,
    I can confirm there is a bug when using Box obstacle type and when the obstacle is at 0,0 :/
    I haven't yet found the cause of this bug, but will dig more into it in the next couple of days and hopefully will be something easy to fix and let you know.
    Sorry about this and thanks for reporting.
     
  14. g3tinmybelly

    g3tinmybelly

    Joined:
    Jul 5, 2014
    Posts:
    6
    @nuverian

    So I was wondering if you had any idea if this asset is compatible with SuperTilemapEditor2D? I am using it to procedurally generate my maps and it automatically generates the colliders with EdgeCollider2Ds. Does this work with the system you currently have in place? Does PolyNav work with procedurally generated content?

    Also, in a post way back in 2014, it mentioned that you did not support varying agent sizes. Do you now?

    Thanks!
     
  15. nuverian

    nuverian

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

    While PolyNav can work for procedural generated content, automatic obstacle creation out of EdgeColliders2D is not possible because PolyNav can work only with either PolygonCollider2D or BoxCollider2D. So if the only option of your tile map editor is to generate EdgeColliders, then unfortunately it can't work out of the box.
    Varying agent sizes are unfortunately not supported, no.

    If you have any other question, by all means do let me know.
    Thanks for your interest in PolyNav! :)
     
  16. Kalgar

    Kalgar

    Joined:
    Sep 17, 2016
    Posts:
    2
    Hi @nuverian !
    I just bought Poly|Nav, and am really enjoying how simple it is to use. However I'm finding I'm having a slight difficulty with my NavAgents. I'm making a top down dual-stick shooter style game, so correct and efficient pathing is quite important!

    I've set up two box-shaped sprites as obstacles, and set up a NavAgent with a few waypoints just to test their movement (they are using the Patrol Random Waypoints script that comes with the demo for the time being).

    It seems that the PolyNav2D object's radius is only affecting my obstacles on their horizontal axes, though - when my agent is moving past, it overlaps when it is directly above or directly below the obstacle! This does not happen when moving on the left or right sides of my boxes, though - it stays away as expected.

    If I am to not add physics to my agents' GameObjects (which seems to be unsupported, which is fair enough), how can I prevent them from overlapping on this axis? I realise that I could always manually make the colliders for the walkable terrain so that they have the spacing I want, however this would only work for levels I hand-design, and I plan on procedurally generating portions of my game!

    I've taken a screenshot from a paused frame of my scene view, to try and demonstrate what's going on. The black hexagon is what I've attached my NavAgent to, and the blue rectangles are my obstacles. Gizmos and debug draw are on, hence the extra lines.

    Any help with this would be awesome! Thanks! pathfinding.png
     
  17. Kalgar

    Kalgar

    Joined:
    Sep 17, 2016
    Posts:
    2
    Having played around with it more, it appears it may have had something to do with the fact that I scaled the blue obstacle object to get it to its current size. Makes sense, now that I think about it more!
     
  18. Spyder638

    Spyder638

    Joined:
    Sep 4, 2014
    Posts:
    6
    Hi @nuverian I am having an issue with Poly|Nav, which is a fantastic addition to any 2d toolkit. I have colliders generated using SuperTilemapEditor2D (The same editor as an above user was asking about).

    These generated colliders are, as far as I can see, solid. However, my agent will walk through the colliders, although, at a slower speed. Obviously, I can't have this happening in the game.



    It only seems to happen in the X-Axis if that makes sense? As in, he'll properly avoid the north and south walls. However, he just warps through the walls on the west and east.

    As you can see in the image on the north wall if the generated collider has to cut off it will do so, and you see a red line through the wall, however, these lines aren't there which means I can only assume there are no hairline gaps.

    I've narrowed the issue down to vertical walls like this:



    (Walls like this are a none issue)

    Have you any ideas what is causing this?
     
    Last edited: Sep 21, 2016
  19. grogshotgames

    grogshotgames

    Joined:
    Aug 6, 2015
    Posts:
    77
    Hi! Do you have any plans to support procedural content?

    As PolyNav2D can only be generated once, and it has only one polygon collider, I can't create procedural dungeons as I don't know how the paths are going to look before generating them.
    It would be great if you could create an independent PolyNav2D per room so I could adjust every polygon collider to every independent room.

    Thank you in advance.
     
  20. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello and sorry for the late reply. :/

    This is pretty weird indeed and something is probably wrong about how your tile editor generated these colliders.
    Is it please possible for you at all, to send me a simple reproduction scene to support@paradoxnotion.com so that I can check it out and see what can potentially be the issue here?
    That would be great if so.

    Thank you!

    Hey!

    PolyNav can already work with procedural content. What you basically need to do for that, is to use the PolygonCollider2D API to set the collider (attached on PolyNav2D gameobject) polygon points.

    The PolygonCollider2D.points define the outer perimeter of the navigation map.

    For Obstacles (holes) you can use that same collider attached on PolyNav gameobject and use PolygonCollider2D.SetPath method to define each inner obstacle. (where every obstacle is a different indexed path)

    After that is done, you simply need to call RegenerateMap() on PolyNav2D. :)

    Let me know if you need any help or clarification with the above.
    Thanks.
     
  21. Spyder638

    Spyder638

    Joined:
    Sep 4, 2014
    Posts:
    6
    @nuverian I probably couldn't as I would have to provide the other asset alongside it which I'm not comfortable in doing.

    Will you be supporting the new collider mashing feature in the 2D experimental features?
     
  22. nuverian

    nuverian

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

    No. By all means that would not be legal or correct. You don't have to include the tile editor. Just the scene with the generated colliders is what I meant.
    Regarding your other question, I am not sure I know which experimental feature you are referring to. Can you please provide a link to further info (I did search but found nothing).

    Thanks
     
  23. Spyder638

    Spyder638

    Joined:
    Sep 4, 2014
    Posts:
    6
    Oh, I see. I'll get back to you with that, as I'm not at my PC with unity on it right now.

    As for the feature I'm talking about:
     
  24. FBones

    FBones

    Joined:
    Aug 28, 2016
    Posts:
    73
  25. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    For whatever reason, I totally missed this post. I am sorry!
    Thanks for the video link. Yes that seems something that would benefit PolyNav a lot and I will certainly look after supporting this!

    Hello,

    This is the documentation file (quite similar to that old one), which is included in the asset:
    https://drive.google.com/file/d/0B9aRtzLh07uwT09weGFOUDJQYkU/view?usp=sharing

    If there is something specifically that you don't see covered, or have any questions about, please let me know.
    Thanks.
     
  26. FBones

    FBones

    Joined:
    Aug 28, 2016
    Posts:
    73
    Thanks, that's all I wanted--- a reference with the updated methods. For example, the explicit "Find Path" method is exactly the sort of thing I thought was available but didn't see in the original document.

    Best,
    FBones
     
  27. FBones

    FBones

    Joined:
    Aug 28, 2016
    Posts:
    73
    Nuverian,
    I thought of something today... just wanted to run it by you:

    It seems that there are 3 heavily requested features that are currently not in Poly|Nav:
    i) Multiple PolyNav 2D meshes

    ii) Ability to assign different sizes to different agents (so, for example, making the navigation allow paths for skinny agents that are impossible for thick agents).

    iii) Having obstacles that only apply to some players and not others.

    I realized today that---perhaps---once you do "i)", the others may come along for free by assigning multiple PolyNav 2Ds to the same area, so long as you could associate obstacles and agents to the specific PolyNav instance.

    For example, say you have a skinny agent with radius 2 and a thick agent with radius 10. Create two PolyNav 2Ds over the exact same area, set one of them to have a radius of 2 and the other to have a radius of 10, and assign the skinny agent to the first PolyNav 2D and the second agent to the second. **viola**, the first agent can go down skinny paths on its Mesh and the thicker one will not be able to do it because those wider paths won't exist on the second Mesh.

    Example for number iii). Say you have some agents that can pass over Grass but not cement and other agents that can pass through cement but not grass. Create two separate PolyNav 2Ds, assign the cement areas as obstacles to the first and assign the grass areas as obstacles to the second. Then assign the agents to the entities that match the corresponding obstacles and **viola** the agents assigned to the first mesh will not be able to pass through the cement, and the agents assigned to the second mesh will not be able to pass through the grass.

    I think the above points to an architecture that would solve the 3 most requested features all at once: a system where there can be multiple PolyNavs 2Ds and obstacles/agents can be assigned to a specific PolyNav.
     
  28. NavarroFamily

    NavarroFamily

    Joined:
    Feb 15, 2016
    Posts:
    15
    What I am trying to achieve is a Grid of tiles with a point and click move system for the player.
    Do you think I could relatively easily create something like this, using PolyNav, and playmaker,
    and keep it clean grid boardgame style movements?


    SEE GIF IMAGES



    When the player is selected, all Valid moves are displayed

    (Valid being moves that player has left this turn, and moves that are un obstructed by a wall)



    When Tile is clicked, player moves along a valid path, until player reaches clicked tile, and stops moving.


    How would I go about making something Like this, with gird movement, wall detection, and displaying valid moves?



    Any point in the right direction would be fantastic!
     

    Attached Files:

  29. nuverian

    nuverian

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

    I am really sorry for the late reply, but somehow I missed those last posts.! :(
    Indeed these are the top 3 requests (especially #1), and you are probably correct that implementing #1 will allow at least for some sort of implementation of the other two as well as some sort of by-product. All your examples really makes sense and it's only a matter of actually trying that out.

    Unfortunately right now though, I am working non-stop on my other assets and before at least some things in their high priority roadmap is done, I will not be able to work on PolyNav, but once these things are out of the way, I will catch up with PolyNav once again.

    Thanks a lot for your thoughts and elaboration on these features!
    Once again, they do make sense indeed :)
    Thanks!

    Hello,
    I am very sorry for the late reply
    Unfortunately for this case, PolyNav is not a grid-based pathfinding solution, which means that the resulting path from the pathfinder, will resemble the closest path from point A to point B (with straight lines) and as such a grid-based like movement is not possible without some heavy changes to the source code, or manually altering the resulting path in code to force make it look like a grid-based movement.

    I'm sorry that PolyNav is not able to work for this type of movement out of the box.
    If there is any other questions you may have, do let me know.
    Thanks.
     
  30. Pypsik1

    Pypsik1

    Joined:
    Jul 16, 2016
    Posts:
    6
    How about dynamic obstacles?
     
  31. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello.
    Wow I missed your post! Sorry about that!
    Dynamic obstacles are not exactly supported, but if you move an obstacle and the RegenerateOnChange option is turned on, then the map will regenerate. For a simple map (few polygons) that is ok, but if there are a really lot of polygons, there is definitely going to be a latency. Here is a video showing what I mean with the RegenerateOnChange option turned on:
     
  32. grogshotgames

    grogshotgames

    Joined:
    Aug 6, 2015
    Posts:
    77
    Hi nuverian! Is there a way to modify the center position of the "avoid radius sphere"? So instead of generating the sphere at the 0,0 position of the gameobject, I could change it to be whatever position I want?
    Thanks
     
  33. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey :)
    I've just send you a PM on how to implement offset for avoidance position.
     
    grogshotgames likes this.
  34. Redden44

    Redden44

    Joined:
    Nov 15, 2014
    Posts:
    159
    Hi, I have a few questions about the asset.

    Can you edit the PolygonCollider2D of the map at runtime via script? I have a scene where I instantiate my procedurally generated dungeons and the size of the dungeons may vary, so I need to be able to edit the PolygonCollider2D that limits the map.

    Can you create an obstacle at runtime via script or you must use the button in the editor? As I said my dungeons are procedurally generated, so I need to instantiate the walls at runtime and set them as obstacles. I read nothing about that in the documentation.

    Can you use a BoxCollider2D instead of a Polygon one for the obstacles? The walls of the rooms have BoxColliders, can I use these instead of the PolygoneColliders?

    Is it possible to make the enemies surround the player using the local avoidance? Let's say the are alredy some enemies on the right side of the player and another one is coming from the same side, is it possible to script the enemy so that it goes around the player and attack him from the left side?

    I read you can't use myltiple layers as obstacles and you're working on an update, will those be included? Is there an ETA for that?

    Thanks.
     
  35. grogshotgames

    grogshotgames

    Joined:
    Aug 6, 2015
    Posts:
    77
    Sent you a PM too!
     
  36. nuverian

    nuverian

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

    Please let me answer your questions.

    - Yes, you can edit the points of PolygonColliders used in runtime and call RegenerateMap() once done. Doing so, will update the navigation map.

    - Yes, you can create obstacles at runtime, but also any object instantiated which have a PolyNavObstacle component attached will also force a map regeneration. So yes, that is definitely possible :)

    - Yes, you can use either BoxCollider2D or PolygonCollider2D for obstacle shapes.

    - The local avoidance in PolyNav is a very simple implementation that simply tries to push agents away from each other. For many cases it will work fine, but unfortunately due to it's simplicity the case you are describing will not be possible to handle that easy. Here is a gif of how it works for your convenience:


    - PolyNav indeed does not make use of layers and every obstacle is considered to be on the same layer. Unfortunately I do not have an ETA for the new version at the moment because other major projects require my full attention right now and I wouldn't like to give any false promises :)

    If you have any other questions, or need any further information, please let me know.
    Thanks!

    I've just replied to your PM :)
     
  37. treshold

    treshold

    Joined:
    Nov 9, 2013
    Posts:
    225
    I was wondering why some events trigger multiple times, for example i have code snippet which is listening navigation start and destination reached events. I put debug.log message on those methods and when I click once new destination, i get debug message about 6 times. Destination reached is triggering just one time.
     
  38. Redden44

    Redden44

    Joined:
    Nov 15, 2014
    Posts:
    159
    Hey, I'm trying to update the PolygonCollider2D of the PolyNav2D at runtime but I have a problem, I can't find RegenerateMap(), there is GenerateMap() and it requires a GenerateMaster. What is that please? The documentation doesn't mention that.
    Thanks.

    Edit:
    I menaged to update the limits of the map at runtime, as you can see in tis picture:


    But I don't think that I'm doing it right, because all my agents are pulled inside a white square, which has the same size of the PolygonCollider2D of the PolyNav2D, before I updated its points (basically a 1 unit square). So there is something wrong in the way I update the map.


    This is the code I use:
    Code (CSharp):
    1. public void UpdatePolyNav()
    2.     {
    3.         Vector2[] newPath = new Vector2[4];
    4.         newPath[0] = new Vector2(_minX, _minY);
    5.         newPath[1] = new Vector2(_minX, _maxY);
    6.         newPath[2] = new Vector2(_maxX, _maxY);
    7.         newPath[3] = new Vector2(_maxX, _minY);
    8.         PolyNav2D.current.GetComponent<PolygonCollider2D>().SetPath(0, newPath);
    9.         PolyNav2D.current.GenerateMap(true);
    10.     }
    As I wrote before I can't find RegenerateMap(), so I'm trying to use GenerateMap(bool generateMaster). What am I doing wrong?

    Also, is it possible to add an offset to the center of the radius of the agent?

    Thanks.
     
    Last edited: Dec 4, 2016
  39. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    Sorry for the late reply.
    OnNavigationStarted is only called once a new destination has been set.
    Are you certain you are not subscribing to the event more than once accidentally?

    Thanks.


    Hello,
    Yes, GenerateMap is the method you need. When I said RegenerateMap in previous post, I actually meant GenerateMap. Sorry for the confusion.

    What you are doing is very correct. The reason why this is happening is because, in awake the map is generated once (with that small size). Then because the "Restrict" option on the agent is set to true, the agent position is being restricted to the current (small and non correct) generated map.

    The easiest thing you can do to avoid that, is to disable "Restrict" option on the agent and maybe turn it back on if you need it, after you have generated the actual level map with the code your posted.

    Regarding an offset, do you mean for the avoidance? If so I've made the required changes and I can send them to you.

    Let me know if that works for you.
    Thanks!
     
  40. Redden44

    Redden44

    Joined:
    Nov 15, 2014
    Posts:
    159
    That's weird, I tried to spawn my enemies after I update the bounds of the map, but they are still pulled in the old one.
    I'm going to try the Restricted solution and see what happens; or maybe I can turn off the generateOnChange of the PolyNav2D and turn it back on after I spawned everything I guess.

    About the offset, yeah I mean the center of the avoidance radius, the pivot point/center of gray circle the red arrow is pointing to:


    I'd like to be able to increase its y position; I write you a pm with my email, thank you very much.

    Edit:
    I "fixed" the problem with the bounds of the map, I think I did some mistakes while I was testing it hehe
    if I spawn the enemies after I update the bounds of the map it works fine. Also If I turn off the auto generation, and turn it on after everything is spawned it works too. Thanks.
     
    Last edited: Dec 6, 2016
  41. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello again,
    Thanks for letting me know that you resolved the issues.
    I've send you the changes requested.

    Cheers!
     
  42. treshold

    treshold

    Joined:
    Nov 9, 2013
    Posts:
    225
    No worries. It was mousedown that triggered it multiple times so i made few if statements and got my problem solved my way ^^
     
    nuverian likes this.
  43. iso250

    iso250

    Joined:
    Apr 19, 2015
    Posts:
    28
    Hey @nuverian.

    I have noticed that some of the NPCs are seemingly hitting the navmesh when they try to round a corner and are getting stuck. It doesn't happen all of the time, but when it does, they just won't move. It's like they're not giving the corners of the navmesh enough berth. The NPCs are set to restrict and closer point on invalid.

    Any idea why this would happen?
     
  44. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    Hmm. Is maybe your Look Ahead Distance way too high? Please try lowering it (or even set to 0) and let me know if that solves the problem.
    Thanks in advance.
     
  45. iso250

    iso250

    Joined:
    Apr 19, 2015
    Posts:
    28
    I've figured it out.

    Square edges, like the one on the left, can result in the look ahead hitting the polynav on the outside of the door. This can result in part of the polynav being closer than where the look ahead hits (namely, the point of the polynav corner). The agent moves toward the point where the look ahead collides with the polynav, resulting in the corner of the polynav being in the way of the agent moving through the door. This makes the agent get stuck.

    Lopping the corners off the polynav, like the example on the right, prevents this from happening. It funnels the agent through the door. It also makes the polynav system more forgiving of longer look ahead distances. (I had to keep my look aheads long due to the sped of the agents. If I reduced their speed then they were overshooting key areas I needed them to hit.)

    I know it may be a lot to code, but having an option to round polynav edges would be very beneficial. It would have to be an option, though, as I'm sure it would be more CPU intensive.


     
  46. firestoke

    firestoke

    Joined:
    Oct 21, 2015
    Posts:
    13


    Hello Developers, I am using Poly|Nav Plugin recently. I have met a problem. As the screenshot, I have a character(agent) and a wall object(obstacle) on the map. When I click a position near the wall object, the character always avoids the obstacle with whole sprite area. But this is not what I want. I have set a box collider rect on the character object, and I expect the obstacle avoidance detection is check the box collider 2d area, instead of the whole character sprite rect. Can you add this feature? Thanks!

    I expect like this.
     
  47. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087

    Hello again,
    Thanks for your explanation. Indeed rounding the obstacles like that would be more intensive, but I will take a look and see what could be done about this situation. Maybe there is another alternative, but I am not sure yet :)
    Thank you.

    Hello,
    PolyNav does not really make use of Physics abd you can completely remove the box collider from the character if you want, since only the pivot of the object actually matters :)
    What I think is happening here, is that the pivot of your sprite is not set to be at it's feet, but rather much higher towards it's head. Could that be the case?
    Let me know.
     
  48. nevaran

    nevaran

    Joined:
    May 21, 2010
    Posts:
    247
    Does this has an 'agent to agent' avoidance/distance ? I need something similar to an RTS game where there are a lot of units being controlled in 2D space, and having something like a dynamic obstacle that is ignored by the agent that it is attached to would be great.
     
  49. firestoke

    firestoke

    Joined:
    Oct 21, 2015
    Posts:
    13
    hmm... Originally, I didn't know the avoidance detection is checking the pivot. Now I get it. Unfortunately, I can't adjust the sprite pivot, because it's put in an atlas image file. So I use a workaround solution that I wrap the original character object into an empty game object to adjust the pivot to the foot position. Now it works as I expected. Thank you!
     
    Last edited: Dec 23, 2016
  50. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    Yes, there is an agent avoidance implementation in PolyNav. Although it is a quite simple implementation, it works fine in most cases. Here is a gif to see it in action.


    Thanks :)

    Hey,
    Thanks for letting me know. I am very glad you solved the issue and things are working as expected now :)