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,038
    Hello and thanks for getting PolyNav.
    PolyNav does not use the Unity Physics engine at all, but it rather uses some simple custom physics for moving the agents on found paths. That means, that PolyNav does not require you to have neither a Collider nor a Rigidbody attached for it to work, but you could attach a Collider and a Rigidbody (set to kinematic) to have the agent interact with other physics objects if required.
    Is that what you meant?
    Thanks!

    Hello,
    As far as I understand the problem from your post, you will please need to invert the PolygonCollider2D, through the option "Invert" that can be found on the PolyNavObstacle component inspector. Please let me know if inverting the PolygonCollider obstacles indeed works for you.
    Thanks!
     
  2. twikzor

    twikzor

    Joined:
    Jul 17, 2017
    Posts:
    5
    Hello,

    I have a project where an AI should try to stay at a set distance from the player. Any suggestions as to how to accomplish that? Picking the closest location at the required distance from the player and rerouting to the closest point does not achieve what I want because the closest point may or may not be at the required distance from the player.
     
  3. nuverian

    nuverian

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

    Probably the simplest solution, would be to set the agent's 'Stopping Distance' property to the distance you want to keep from the target, and let the agent pathfind to the target actual position. :)
     
  4. ChrisTobiS

    ChrisTobiS

    Joined:
    Jun 15, 2017
    Posts:
    12
    Hey nuverian :), are there any news about the improved agent-avoidance and a tilemap/composite-collider compability? Because I really need those and I'm afraid without a better agent-avoidance system this asset is not right for my game.
     
  5. twikzor

    twikzor

    Joined:
    Jul 17, 2017
    Posts:
    5
    That shouldn't work if the agent is WITHIN that Stopping Distance, correct? The player can move faster than the agent at times.
     
  6. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,084
    Just a quick question. Imagine this scenario:

    1) We have an adventure game
    2) You can control the player by clicking the mouse at a point. The character will move to that point.

    Now this is what is also shown on some of the promo videos for this tool, so far so good.
    But here's the question and I'm asking myself if this tool would be the right choice for doing this:

    3) the player has also the possibility to move around with a controller (Xbox Controller or PS4 Controller etc.)

    meaning - in the end the type of input should be irrelevant for the movement logic, right? In the end I'd like to use this tool to steer the character with a controller and other npcs/enemies should just steer on their own.
     
  7. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    507
    That's doable. You have to code it. I have spacecraft that can be controlled directly by touch or controller, or follow a PolyNav path for AI where I control turn and thrust using the path nodes as waypoints.
     
    nuverian and BTStone like this.
  8. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,038
    Hey!
    Unfortunately the other projects (NodeCanvas, FlowCanvas, Slate) took most of my time working on them in the last couple of months, so sadly I don't have any news on the PolyNav agent avoidance and tilemap improvements yet :( I don't want to promise anything I can't keep, but I expect to be able to work on PolyNav new version once again, with the coming of February. Please accept my apologies on the delay.
    Thank you!

    Hey,
    Yes, that is correct. It was a rather simple approach to the problem. A more correct and dynamic approach, would be to calculate the desired destination position that is at a certain distance from the target. What I would probably try, is something like this:

    - If the agent is closer than the desired distance, find the position by getting the direction from the target and to the player normalized, then multiply that by the desired distance. This will result in the closest position for the agent, that is at the desired distance from the target.

    - If the agent is further away than desired distance, I would just set the destination to the target position. Thus when the agent get's closer than the desired distance, the first part of the code above, will fire, thus changing it's destination to be further away.

    It's a very simple approach of course, bit it's a basis upon which tuning can be made :)
    Code (CSharp):
    1.     void Update() {
    2.         if (target != null){
    3.             if (Vector2.Distance(agent.position, target.position) > keepDistance ){
    4.                 agent.SetDestination( target.position );
    5.             } else {
    6.                 var direction = (agent.position - (Vector2)target.position).normalized;
    7.                 var offset = direction * keepDistance;
    8.                 var keepDistancePosition = (Vector2)target.position + offset;
    9.                 agent.SetDestination( keepDistancePosition );
    10.             }
    11.         }
    12.     }

    Thanks.

    Hey,
    Just like @Shifty-Geezer said, yes that is totally possible to do with a bit of coding for controlling the character directly with the controller, or tell it to pathfind with PolyNav :).
    If you encounter any problems implementing what you are after, just let me know.
    Thanks.

    Thanks! :)
     
    BTStone likes this.
  9. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,084
    Thanks for the reply! Just to get it right, maybe I should precise what I exactly have in mind. I want to control the character freely with the controller and not on specified path points. Like you would expect. You're pushing the Analogstick up, character goes up. pushing to the right,character goes to the right, diagonal push going diagonally and so on, no predefined path.
    The intended use of PolyNav would be to setup the scene and it's boundaries, while the agent would move freely within these boundaries in compliance to my inputlogic, which is linked to the agent. As Shifty-Geezer mentioned, that should be possible, right?
     
  10. peachpieproductions

    peachpieproductions

    Joined:
    Sep 2, 2017
    Posts:
    14
    Hey there Nuverian! Amazing product!

    I am using this for a tower defense style game, and once there becomes a complex path, and 20-30 enemies, the "repath()" method starts slowing down the game (info from profiler).

    I was curious if there would be a way to generate one path, that they all could use?

    Then I could just update the 1 path frequently and they could all follow it, since its tower defense, they all use the same path anyways.

    Thanks a bunch! :)
     
  11. Xaon

    Xaon

    Joined:
    Feb 28, 2013
    Posts:
    53
    Hello.
    Is there a way to visualize generated navmesh? On some of my maps agents behave like there was no navmesh in some parts. Please, look at the pictures below. Agent goes near the area market as red and then stops as if there was an obstacle.
    All obstacles are setup with the same parameters (beside polygon collider shape).
    I also had an issue that navmesh didn't work until I've added at least one obstacle.
    I'm using Unity 2017.3.
     

    Attached Files:

  12. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,038

    Hello and sorry for the late reply!
    PolyNav does not include any code that will help you in creating your non-pathfinding controller (free direct movement for example), so you will have to code when to use pathfinding and when not to, thus use the direct controller input. You can however still restrict the movement/position of the character within the predefined navigation area boundaries even when not using pathfinding.

    Hello and sorry for late reply! Thanks, I am glad you like PolyNav :)

    Hmm. You could use the 'PolyNav2D.current.FindPath' method, to find a single path (Vector3[]) from point A to point B, and then have the agents follow that Vector3[] path with some custom code directly. Thus in this case you wouldn't even require to have the PolyNavAgent component attached on your agents, but instead you would directly find a single path and write some simple custom code to have your agents follow it :)

    If you need help with writing a method that makes a gameobject follow a Vector3[] path, just let me know.

    Thanks.


    Hey,

    Visualizing the navigation area more properly (eg solid color), is not possible right now, but is something I am looking after implementing.
    Regarding the problem you are facing, is it possible for you to please send me that same level you are having a problem with, so that I can check what is going on wrong there? If so, please do send me an email to "support_AT_paradoxnotion.com".
    Thanks!
     
  13. drunkenoodle

    drunkenoodle

    Joined:
    Nov 11, 2012
    Posts:
    16
    Hiya Nuverian, is there an event/callback, etc that PolyNav fires after it's finished initially generating the nav obstacles? I'm in an edge-case where I dynamically generate a small (ish) map but there's a bit of a stutter when it initially instantiates all of the obstacles and PolyNav does its preliminary calculations.

    Not a massive issue to be honest but I figured if there's an easy way to make the scene fade wait for it to finish doing its thing, it'll look nicer.

    Cheers!
     
  14. validname1

    validname1

    Joined:
    Feb 1, 2018
    Posts:
    23
    Hey there. Is the documentation up anymore?
     
    Last edited: Feb 3, 2018
  15. nuverian

    nuverian

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

    Since the generation is not async yet, thus basically done in the same frame in which RegenerateMap() is called, there is no such event, but I can add an event if it helps :)

    Thanks.

    Hello,
    I've updated the online link to the current documentation included. Here you go:
    https://drive.google.com/file/d/120M2csM2dA6uPVdg_ZIU0BSsPuJKVQJW/view?usp=sharing

    Thanks.
     
  16. drunkenoodle

    drunkenoodle

    Joined:
    Nov 11, 2012
    Posts:
    16
    Thanks mate, well it's no massive issue so should it be a side-item that can be added in future without too much trouble, it will definitely come in handy. In the meantime I've just been working on optimizations which seem to have cut the time down by about 40% or so (at a guess :p).
     
    nuverian likes this.
  17. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    507
    I'm running into an issue with dynamic level and object scaling. I've a bunch of scenery objects which have a PolyNav object as a child that defines the PolyNav map, and this works fine until I scale the objects. When I do this, the PolyNav radius is scaled similarly. So where I want a distance of 3 around my nav colliders, an object with scale (2,2,2) causes a distance of 6 around my nav objects.
     
    nuverian likes this.
  18. nickproud

    nickproud

    Joined:
    Jun 21, 2017
    Posts:
    4
    Hi!

    Great product.

    Just a small issue you may have an idea of how to solve. I have a single point that spaceships will be travelling to but they avoid each other slightly. This works great and so if a ship is currently on the point another ship coming in will arrive and stop nearby. That is good. However, each ship has a call back for onDestinationReached(). It seems that because i have had to set a stopping distance greater than the avoidance radius (in order for the ships to stop near but not on top of each other) any ships moving to the point after the first one do not fire the OnDestinationReached event as they have technically not reached their destination (they have just stopped.) How can I make this event fire or fire a similar one to allow me to use callbacks for any agents stopping near to the destination but not on it because of avoidance?
     
    nuverian likes this.
  19. nuverian

    nuverian

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

    It's not problem at all. I've just added the event. It was rather easy to add really :)
    You can if you want, open up PolyNav2D.cs and add the event likeso:
    Code (CSharp):
    1. public static event Action<PolyNav2D> onMapGenerated;
    Then in the GenerateMap method at the very end of the method place this to raise the event.
    Code (CSharp):
    1.             if (onMapGenerated != null){
    2.                 onMapGenerated(this);
    3.             }
    Thanks! :)

    Hey,
    Good call. The radius should be fixed rather than scaled. To change this, please open up PolyNav2D.cs and in the method "CreatePolyMap" and within the iteration at line #219, change the code:

    From this:
    Code (CSharp):
    1.                 var rad = radiusOffset + obstacle.extraOffset;
    2.                 var points = InflatePolygon(obstacle.points, rad);
    3.                 var transformedPoints = TransformPoints(points, obstacle.transform);
    4.                 obstaclePolys.Add(new Polygon(transformedPoints));
    To This:
    Code (CSharp):
    1.                 var rad = radiusOffset + obstacle.extraOffset;
    2.                 var transformed = TransformPoints(obstacle.points, obstacle.transform);
    3.                 var inflated = InflatePolygon(transformed, rad);
    4.                 obstaclePolys.Add(new Polygon(inflated));
    Let me know if that is indeed what you were referring to and if that works for you.
    Thanks.

    Hello,

    Thank you. I am glad you like PolyNav :)

    It's a tricky situation. I've come up with a few source code changes that keep track of the amount of time in seconds that an agent is actively avoiding other agents and if that time elapsed doing so, is greater than a "maxAvoidanceStuckTime" property of the agent, then the agent will Stop(), and either:
    A) Consider the path invalid ('OnDestinationInvalid' raised), if destination position is far enough, or
    B) Consider the path valid ('OnDestinationReached' raised), if destination position is close enough.

    "Far/Close Enough" in the above situation, is determined by the remaining path distance compared to a "considerReached" agent property, although, I think that the path should always be considered Invalid when due to other agents being in the way, no matter the remaining path distance.

    Let me know what you think. If you like, I can send you the changed code.
    Thanks :)
     
  20. nickproud

    nickproud

    Joined:
    Jun 21, 2017
    Posts:
    4
    Could be a great solution. Would you mind sendng me your code changes?
    Also, another quick question. Do you have an easy way to change the properties of all agents? Say for example, the speed for all agents in a scene?
     
  21. drunkenoodle

    drunkenoodle

    Joined:
    Nov 11, 2012
    Posts:
    16
    Thanks very much this nuverian, I'll give it a whirl!
     
    nuverian likes this.
  22. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    507
    Yeah, that seems to be it. Thanks!
     
    nuverian likes this.
  23. SteenPetersen

    SteenPetersen

    Joined:
    Mar 13, 2016
    Posts:
    26
    Hi Nuverian, Great product so far. I have an issue atm which I have narrowed down to being polynav related. I am making randomly generated dungeons for my game and all walls have a polynav object and collider on them. It all works correctly but there are significant load times. I have tried making them all children of one object that makes a composite collider out of the children but the load times are still significant. Im wondering if there is anything I can do to drastically reduce this load time?

    thanks.

     
    drunkenoodle likes this.
  24. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,038
    Hello and really sorry for late reply.
    I have just send you a PM.
    Regarding your new question, all active agents in the scene, are cached in a static List<PolyNavAgent> on the PolyNavAgent class, but the list is private. You could if you want, simply make it public and then in some code of yours, iterate the list and set the agent properties altogether.

    Thank you!


    Hello,

    Thank you.
    Hm.. Building the map can indeed be slow depending on the number of obstacles.
    Are all tiles seen in the screenshot a separate obstacle object?
    This will certainly improve when support for compound colliders is there, but unfortunately I didn't have the time to work on the implementation just yet.

    Let me know.
    Thank you!
     
  25. Getfreeze

    Getfreeze

    Joined:
    Jul 28, 2014
    Posts:
    4
    Hello, I have bought your assets and combined with Behaviour Tree. Works like wonder while Im trying to build a RTS game. How ever I encounter abit problem, when alot of unit stack nearby, they tent to keep moving by abit, I was expecting they will stop moving.(See video below and attachment for the polynav setting). I tried to ask for support from Behaviour tree team, but they could not help me on this matter.



    Could you assist me in this matter? And how could I email you if I have further question?

    Kind regards,
    Stev
     

    Attached Files:

  26. twikzor

    twikzor

    Joined:
    Jul 17, 2017
    Posts:
    5
    That did solve my issue. As a follow up: let's say the agent in question is trying to navigate away from the player but the destination closest point at the set distance away from the player is unreachable, behind a wall for example, so the agent reroutes to a reachable point at that distance. Is there any way to get the position of the new destination, the reachable one? Specifically, I have a problem where one agent teleports through walls, but if asked to walk to the same location reroutes instead.

    Also, in the following code there seems to be a buffer of about 3 units where the agent does not move. Why is that and is there any way to detect when that is happening?
    Code (CSharp):
    1.  if (playerReference != null)                                                                                                              
    2.         {
    3.             if (Vector2.Distance(agent.position, playerReference.transform.position) > keepDistance)
    4.             {
    5.                 agent.SetDestination(playerReference.transform.position);
    6.             }
    7.             else
    8.             {
    9.                 var direction = (agent.position - (Vector2)playerReference.transform.position).normalized;
    10.                 var offset = direction * keepDistance;
    11.                 var keepDistancePosition = (Vector2)playerReference.transform.position + offset;
    12.                 agent.SetDestination(keepDistancePosition);
    13.             }
    14.        
     
    Last edited: Feb 28, 2018
  27. nuverian

    nuverian

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

    Thanks I am glad you like PolyNav.

    The reason they are still moving a bit, is because each of the soldiers is actually still trying to go to the target destination position, but is pushed back due to the other soldiers being in the way.

    A more "proper" solution I think, would be for each of the soldiers to have it's own target destination within a "formation" you want the soldiers to achieve.

    But maybe you are after something a bit more "loose" (no formations).
    There have been some improvements to the avoidance system lately which I think will help in what you want to achieve.
    I can send you the new version to test it out if you want. If so, (and for support) just send me an email to "support_AT_paradoxnotion.com" :)

    Thanks.

    Hey,

    To get the position of the new "reachable" destination, you can simple get the "PolyNavAgent.primeGoal" property. This property returns the current destination goal (Vector2).
    Is that what you've actually asked about? :)

    Regarding the sample code, I've tested it out and seems to be working correctly. Hmm. Can you please explain what the problem is by saying "buffer of about 3 units where the agent does not move"?

    Thanks.
     
  28. twikzor

    twikzor

    Joined:
    Jul 17, 2017
    Posts:
    5
    Hi,

    What I mean by that is, if the distance between the player and the agent is higher than keepDistance, the agent moves as necessary. However, with a keepDistance of 10, for example, if the distance between the player and the agent is smaller than keepDistance, the agent only begins moving when the distance reaches 7ish.

    And yes, primeGoal is what I was looking for.
     
    nuverian likes this.
  29. Vaulcul

    Vaulcul

    Joined:
    Apr 3, 2016
    Posts:
    32
    Hi,

    Is there anyway to get Poly|Nav to work with the Unity Tilemap Collider (and also the composite collider that they suggest using, which is pretty much just a Polygon collider)?

    Everytime I attempt to add Poly|Nav to my map area, it removes the tilemap collider and replaces with a polygon/box collider... Which doesn't really work for the Tilemap system.

    Thanks much
     
  30. nuverian

    nuverian

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

    PolyNav will be possible to work with Composite Collider in the next version, yes. The ability is already implemented.
    If you don't want to wait for the new version to hit the asset store, you can just drop me an email with your order ID and I can send the new version to you in advance :)

    Thanks/
     
  31. twikzor

    twikzor

    Joined:
    Jul 17, 2017
    Posts:
    5
    Hi,

    I've made a gif to show what I mean. You can see the distance between the player and the agent in the console and that the agent moves when that distance grows to over 10 or below 7ish(I'm not sure what value exactly). The distance the agent should keep is 10.

    if (playerReference != null)
    {
    if (Vector2.Distance(agent.position, playerReference.transform.position) > keepDistance)
    {
    agent.SetDestination(playerReference.transform.position);
    }
    else
    {
    var direction = (agent.position - (Vector2)playerReference.transform.position).normalized;
    var offset = direction * keepDistance;
    var keepDistancePosition = (Vector2)playerReference.transform.position + offset;
    agent.SetDestination(keepDistancePosition);
    }
    }


    This is the code used to move the agent. keepDistance is a public float assigned from the inspector. The code does go into the else part properly, but the movement does not happen.

     
  32. theuncas

    theuncas

    Joined:
    Feb 21, 2015
    Posts:
    23
    Hello,
    I just purchased this asset. It works fine and it's simple to use BUT there is an issue when using lot of units with the same target point.

    Some of my units are stopping on the way with no reason.... The only way to avoid this is to set "Avoid Radius" to 0 but, all my units are overlapping..

    I can share you an exemple if needed, but for me there is no reason that they stop... I need some help with this issue.
    Thx
     
  33. nuverian

    nuverian

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

    Hmm. I have just copy pasted your code and used it in the example scene that come with PolyNav, and the results I think are what to be expected as shown bellow:
    AvoidTarget.gif

    Can you please send me the project you are using to "support_AT_paradoxnotion.com" so that I can closer inspect what could be going wrong (since there is definitely something off)?:)
    Thank you.

    Hello,

    Thanks for getting PolyNav.
    The issue you are experiencing is due to the "Avoidance Consider Stuck Time". This parameter denotes the max time that the agent can be actively and constantly colliding/avoiding other agents before the system considers the agent as being stuck.
    Increasing this parameter to something high, will avoid the issue you are experiencing.

    Please let me know if that was indeed the case.
    Thank you.
     
  34. Getfreeze

    Getfreeze

    Joined:
    Jul 28, 2014
    Posts:
    4
    Hello, please send me the new version to test out at getfreeze1981_AT_hotmail.com, thanks for the help!
     
  35. Caffeen

    Caffeen

    Joined:
    Dec 25, 2013
    Posts:
    28
    Just FYI, your "Documentation" link in the main post is broken.
     
    nuverian likes this.
  36. JSwanFin

    JSwanFin

    Joined:
    Apr 10, 2013
    Posts:
    16
    We use polynav in our game project. I have customized it a bit for better fit for our needs. Everything works quite well and smoothly, however, there is a case where we would like to remove an obstacle on the fly. Think like a door that opens. At least previously re-calculating the map was quite heavy operation and our levels are quite complicated.

    I was wondering if there is a lighter way to handle that case now after few updates, before I update the plugin and customize the source. Particular I am interested on how multiple map support works, but I can't seem to find any documentation on it.
     
  37. theuncas

    theuncas

    Joined:
    Feb 21, 2015
    Posts:
    23
    Hello, thx you for your fast reply. Your answer was helful. I'm no more facin this issue. Thx you !
     
    nuverian likes this.
  38. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    54
    Hi everyone, this asset is great and I would like to use it for the first time in my game. I would like to create a procedurally generated maze. Does anyone have any info whether I can do this with PolyNav dynamically? Any examples or source code available specific to PolyNav? Thanks in advance!
     
  39. validname1

    validname1

    Joined:
    Feb 1, 2018
    Posts:
    23
    I have it working on a procedurally generated map. Simply place the vertices of the polynav in the correct boundaries and run the generatemap function.
     
    nuverian likes this.
  40. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,038
    Sorry for late replies everyone. I was quite ill for the last few days.

    Thank you.
    Fixed.

    Hey,

    The re-generation times have not been greatly improved within the last few versions, so it might not be worth it to update only for this reason in case you have modified the source.

    With multiple maps support now, you can have different agents navigate within different navigation maps. Thus you can have multiple navigation maps created in the scene and different agents navigating about those different maps. You can also on the fly change the "target map" of the agent to use another map. This could theoretically be used to substitute obstacles, but using this feature for doors for example like in your use case is definitely an overkill and non-convenient.

    The most important change that could be made for what you are after, would be to make the re-generation run on a different thread, but I still haven't got my head around in doing this correctly, considering the amount of refactoring that is required to do so as well. :/

    Thanks!

    Hello,

    Thanks. I am glad you like PolyNav.
    Yes, you can use PolyNav for procedural generated maps.

    A navigation map in PolyNav, is simply defined as a polygon for the "base map" and optional multiple polygons for the "obstacles". Here is the example script that is included in PolyNav for manual map creating (both editor and runtime):
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3. using PolyNav;
    4. using Polygon = PolyNav.PolyNav2D.Polygon;
    5. using PolyMap = PolyNav.PolyNav2D.PolyMap;
    6.  
    7. //You can provide a custom PolyMap to PolyNav for usage. Doing this disregards all PolyNavObstacles.
    8.  
    9. [ExecuteInEditMode] // <- This is not required of course, but only to visualize the resulting map in editor.
    10. public class CustomMapProvider : MonoBehaviour {
    11.  
    12.     void OnEnable(){
    13.  
    14.         //Clockwise points of master polygon.
    15.         var masterPolyPoints = new Vector2[]{ new Vector2(-10, -10), new Vector2(10, -10), new Vector2(10, 10), new Vector2(-10, 10) };
    16.         var masterPoly = new Polygon(masterPolyPoints);
    17.  
    18.  
    19.         var obstaclePolygons = new List<Polygon>();
    20.  
    21.         //Counter-Clokwise points of obstacle polygon.
    22.         var obstaclePoints = new Vector2[]{ new Vector2(-5, -5), new Vector2(-5, 5), new Vector2(5, 5), new Vector2(5, -5) };
    23.         var obstaclePoly = new Polygon(obstaclePoints);
    24.         obstaclePolygons.Add(obstaclePoly);
    25.        
    26.         ///Create more polys here
    27.         ///Create more polys here
    28.  
    29.  
    30.         //Create the PolyMap.
    31.         var map = new PolyMap(masterPoly, obstaclePolygons.ToArray());
    32.  
    33.         //Provide the map.
    34.         PolyNav2D.current.SetCustomMap(map);
    35.     }
    36. }
    37.  
    While PolyNav works with PolygonCollider2D for "drawing" the map in editor time, the above solution does not require them at all and also works in runtime.

    Another way, like @validname1 probably meant, would be to set the PolygonCollider2D points of both the "base map" as well as the obstacles directly and then indeed calling GenerateMap().
    Depending on the use case you might want the first solution, or if also having PolygonCollider2Ds is desired, the second.

    Let me know if you have any questions.
    Thanks.
     
  41. Kathar3D

    Kathar3D

    Joined:
    Aug 24, 2014
    Posts:
    8
    Sorry, silly question I'm sure, I did have a quick search but couldn't see an answer to this - I'm basically producing a 3D isometric game, and wanted to use this asset as I've heard really good things (and I don't need to worry about 3D/height in my game as all players/enemies will be on the same plane/level). But as it's obviously oriented towards 2D games, the axis are obviously based around X/Y, and not X/Z as I have set up. Is there an easy way to set Unity/PolyNav to work on the X/Z axis for the colliders and such, or will I just have to bite the bullet and reorient everything, and change the gravity direction etc?

    Thanks for any help!

    Edit: Have just gone ahead and changed the orientation of everything to X/Y, all good and PolyNav is working great, thanks!
     
    Last edited: Apr 27, 2018
  42. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,038
    Hey,
    Thanks a lot. I am glad to hear you've moved forward with your project using PolyNav :)
    If you encounter any questions, just let me know.
    Thank you!
     
  43. nopogo

    nopogo

    Joined:
    Sep 9, 2012
    Posts:
    15
    Any possibility of this working with a "hollow" obstacle? I'm using the new Tilemap feature in unity for my level. This auto generates a composite collider based on the sprites. I'd hoped it would be as simple as adding a PolyNavObstacle to the tilemap that contains the walls, but alas. It seems that because the walls form an enclosed structure (see image) the nav-agent tries to get out of the obstacle and isn't able to navigate within it (until I remove one of the outer walls)

    question.png
     
    Last edited: May 7, 2018
  44. validname1

    validname1

    Joined:
    Feb 1, 2018
    Posts:
    23
    Hi, I've noticed that I get *massive* slowdowns when I attempt to run GenerateMap() on large procedurally generated maps. Is there any optimization tricks you'd recommend? Async doesn't appear to be a proper solution since Unity has these odd limitations on what can be ran on a different thread than the main one.
     
  45. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,038
    Sorry for the super late reply but apparently I've missed your post. What you are after should be made to work.
    I will look into this, fix it and send a new version to the asset store as soon as it's done.
    Thanks for letting me know and once again I am really sorry for missing your post!

    Hello. GenerateMap can indeed be slow depending on the number of obstacles and corner vertices/nodes created upon generation, but map generation, is really meant to only be called once upon loading the game/scene and not be used dynamically. What degree of slowdown are we talking about more or less?
    Thanks.
     
    johanneskopf likes this.
  46. BrothaMan

    BrothaMan

    Joined:
    May 19, 2013
    Posts:
    47
    @nuverian

    A couple questions on using Polynav with physics.

    1. We noticed that Polynav2D directly sets the position of a transform on a gameobject. If a gameobject has a rigidbody2D, it is highly recommended for performance reasons to utilize rigidbody2D.MovePosition(Vector2) when moving the gameobject. With the current Polynav2D implementation, do you recommend that gameobjects with Polynav2D movement should not have a rigidbody2D? The performance cost is also an assumption our side after researching Unity documentation. If you dont feel this is a performance cost, we like to hear your opinion as well.

    2. If that's the recommendation, we have scenarios where we currently use polynav2D movement with a dynamic rigidbody2D AI character. As we are in the stages of optimizing our game, we were wondering how feasible it would be to change all transform update calls to rigidbody2D.MovePosition(Vector2) if rigidbody2D is attached? If feasible, is this something we can change on our side and you can point us to the areas we should make this change? And is this a possible feature you can add to the asset?

    Thanks!
     
    tosiabunio likes this.
  47. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    52
    Hey,

    For me the CompositeCollider2d isn't working as I think it should.
    When I add a CompositeCollider2d and 2 PolygonColliders2d (usedByComposite set to true) to the GameObject with the PolyNav2D on it, then they won't be combined, and PolyNav only uses one of the PolygonColliders.

    Correct (without PolyNav2D script on them):
    correct.PNG

    Incorrect:
    incorrect.PNG

    Or is there another way how this should/can be accomplished?

    Edit: I use Unity 2018.1.1f1

    Thanks in advance,
    John
     
    Last edited: May 28, 2018
  48. Kathar3D

    Kathar3D

    Joined:
    Aug 24, 2014
    Posts:
    8
    Brilliant asset this, been using it in my game and was very easy to setup and easy to use.There's just one final bit of functionality I need to implement in my game using PolyNav, and I'm just wondering if there's a way to do it currently.

    I've basically set up a stealth system of sorts, and I currently have enemies patrolling to set waypoints using PolyNav. They also have a line of sight system, so when they see a player they start running towards you. This is all working great, but I also want to have a 'sound' aspect to it too. So if the enemies hear a player's gunshot they'll come running towards the sound. I have this kind of working, but I want it to be distance based using PolyNav's pathfinding, so if the enemy is too far, they'll ignore the sound. Thing is, I'm using PlayMaker, and I almost feel like I need another Action to 'test' a distance to a GameObject/Position. I know there's the Get Remaining Distance Action, but I'd have to quickly change the enemies target to check the distance using that, and I don't want the enemies to be visibly interrupted from their patrolling behaviour while they check if the sound is too far.

    I might be missing something super obvious, so figured I'd ask here. Or is it just the case that I'd need a new Action for this? Any help/thoughts would be really appreciated! Thanks a lot!
     
  49. nopogo

    nopogo

    Joined:
    Sep 9, 2012
    Posts:
    15
    No worries. You reply at least :), thanks! Will unity let me know there is an updated version of an asset packet or do I need to keep an eye out myself? (i.e. do you post anywhere there is a new version available)
     
    Last edited: May 29, 2018
  50. nak-dev

    nak-dev

    Joined:
    Aug 7, 2015
    Posts:
    22

    So, I hope this helps. I got it working for my procedural dungeon, but actually created a composite out of the navmesh obstacles. I couldn't get it working with the master polygon, but tried. I made the master polygon public in the inspector and everything looked like it was hooked up correctly, but it doesn't generate correctly.

    Edit:
    So I finally the obstacle navmesh working.
     
    Last edited: Jun 9, 2018
    nuverian likes this.