Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Poly|Nav: Pathfinding for Unity2D

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

  1. nevaran

    nevaran

    Joined:
    May 21, 2010
    Posts:
    247
    It seems its going out of it's borders slightly when trying to avoid units?
     
  2. ciaravoh

    ciaravoh

    Joined:
    Dec 16, 2009
    Posts:
    252
    Hi,

    I just bought your tool and it's very usefull. I have one question. when an Agent is avoiding other agent, it is rotating randomly. How can I avoid this ?

    Thank you for your work and your help.

    Hervé

     
  3. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    Hello,
    Hmm. I am not sure what you mean. Can you please explain a bit? :)
    Thanks in advance.

    Hello,
    Thanks for getting PolyNav.
    The agent avoidance system in PolyNav is quite a simple implementation and this can happen if two or more agents are competing over the same spot. Do both cars have the same target destination?
    One thing you can try to do, is to have a Stopping Distance slightly bigger than the avoidance radius is.
    Let me know.
    Thanks again.
     
  4. ciaravoh

    ciaravoh

    Joined:
    Dec 16, 2009
    Posts:
    252
    Hello,

    Same behaviour. And I could have a lot of car behind the first one. what would be the solution ?

    thank you.
     
  5. ciaravoh

    ciaravoh

    Joined:
    Dec 16, 2009
    Posts:
    252
    yes, the cars have the same target. And it will be the case for plenty of cars :)
     
  6. banksazero

    banksazero

    Joined:
    May 8, 2015
    Posts:
    77
    Hello
    I have purchased poly|Nav 2d .Now I have 2 questions
    1.I'm interested in dungeon generate (dungen,daedalus, dungeon architect) How I use polyNav with this (like generate map at runtime how I draw Map for walk and obstacles for avoid)
    2.How I get Z rotate ( my game is 2.5d I would like to change animation sprite when Z rotate 45 90 135 180 degrees but if I enable rotate transform my sprite rotate too I dont want it rotate but want to know target of Z target)

    Thankyou

    If you don't understand something please let me know I'll try to explain
    I'm foreign
     
  7. ArmelGibson

    ArmelGibson

    Joined:
    Jul 4, 2015
    Posts:
    8
    Hey

    I purchased PolyNav a few days ago, and while it looks like it's exactly what I needed, it sometimes behaves very weirdly.

    Here is a simple example, where I give a SetDestination to a PolyNavAgent, expecting it to avoid an Obstacle:



    I've tried with different configurations for the obstacle, and this is not a a problem related to this specific shape.

    Here's my agent:



    This is as gamebreaking as it can be, as several of my characters are moving very weirdly when going from A to B.

    Thanks in advance!
     
  8. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    Hello again and sorry for the late reply.
    Unfortunately the only solution here to avoid cars fighting over the same spot with avoidance, would be to increase to "stopping distance" of the cars to something at least higher than the avoidance radius that they have.
    I hope this solves the issue for you.
    Thank you.

    Hello and thanks for getting PolyNav :)
    Let me address your questions:

    1) To alter the map in runtime, all that is really needed is to set the points of the PolygonCollider2D attached on the PolyNav gameobject or the PolyNavObstacle gameobjects, simply by using the PolygonCollider2D API (.points, SetPath) and then call "PolyNav.current.GenerateMap(true);".

    2) For such things, you most probably want to use the "movingDirection" property of PolyNavAgent, which return the direction normalized vector. There is also a simple example script included for it's usage called "DirectionChecker". :)

    Let me know if these work for you.
    Thanks.

    Hello and thanks for getting PolyNav :)

    This definitely looks very weird.
    It looks to me like the character is also moved by means other than just the PolyNavAgent script. Do by any chance you have a rigidbody component attached on that character? It seems like there is an upward force of some kind.
    Also, please try and decrease the Look Ahead Distance as it currently seems to be quite big.

    Let me know.
    Thanks.
     
  9. tataragne

    tataragne

    Joined:
    Aug 15, 2009
    Posts:
    27
    Hello,

    We are looking for a unity 5 plugin able to make 200 agents navigate in a 2D space avoiding statics obstacles, dynamics obstacles and others agents. This is for a mobile game. The result must be smooth (60 fps minimum). Is it possible to make this type of game with this plugin ?

    regards,

    Adrien
     
  10. ArmelGibson

    ArmelGibson

    Joined:
    Jul 4, 2015
    Posts:
    8

    Okkk really sorry here, there was some manual transform changes that were happening in a obsolete part of my code. PolyNav is awesome so far, thanks!
     
    nuverian likes this.
  11. ciaravoh

    ciaravoh

    Joined:
    Dec 16, 2009
    Posts:
    252
    Hello,

    I may have the solution to my problem. I added a test to know if the agent in front of me is closer than the LookAheadDistance and I adjust my velocity to its velocity. When the first agent reach it's target, it stops. Then the agent behind him will mimic his behavior.


    Code (CSharp):
    1.  void LookAhead(){
    2.  
    3. if (lookAheadDistance <= 0)
    4. return;
    5.  
    6. var currentLookAheadDistance= Mathf.Lerp(0, lookAheadDistance, velocity.magnitude/maxSpeed);
    7. var lookAheadPos= position + velocity.normalized * currentLookAheadDistance;
    8.  
    9. Debug.DrawLine(position, lookAheadPos, Color.blue);
    10.  
    11. if (!polyNav.PointIsValid(lookAheadPos))
    12. velocity -= (lookAheadPos - position);
    13.  
    14. if (avoidRadius > 0){
    15. for (int i = 0; i < allAgents.Count; i++){
    16. var otherAgent = allAgents[i];
    17. if (otherAgent == this || otherAgent.avoidRadius <= 0)
    18. continue;
    19.  
    20. var mlt = otherAgent.avoidRadius + this.avoidRadius;
    21. var dist = (lookAheadPos - otherAgent.position).magnitude;
    22. var str = (lookAheadPos - otherAgent.position).normalized * mlt;
    23. var steer = Vector3.Lerp( (Vector3)str, Vector3.zero, dist/mlt);
    24. velocity += (Vector2)steer;
    25.  
    26. if ((lookAheadPos - otherAgent.position).magnitude < lookAheadDistance) {
    27. velocity = Truncate (velocity, otherAgent.velocity.magnitude);
    28. Debug.Log ("--" + this.gameObject.name + ":" + velocity + "--" + otherAgent.velocity);
    29. Debug.DrawLine (otherAgent.position, otherAgent.position + str, new Color (1, 0, 0, 0.1f));
    30. }
    31. }
    32. }
    33. }
     
    nuverian likes this.
  12. banksazero

    banksazero

    Joined:
    May 8, 2015
    Posts:
    77
    Before you suggest me I give enemy always look at player it look terrible when enemy avoid obstacles still look at player.
    After I try everything look good.

    Thank you nuverion
     
    nuverian likes this.
  13. ciaravoh

    ciaravoh

    Joined:
    Dec 16, 2009
    Posts:
    252


    Hello,

    Me again :)

    I'm struggling to get this done. more than 1 agent try to reach the same target. the first one is fine. the second one will slow down when arriving behind car 1 but it's shaking. Car 3 is also shaking of course. How can I avoid this ?

    thank you.
     
  14. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    Hello,
    Except from Dynamic/Moving Obstacles which PolyNav does not support, the rest of the specs you posted should be handled fine. Just to clarify, only static obstacles are really supported by PolyNav.
    If you have any other questions or want to elaborate on the above, just let me know.
    Thanks. :)

    Hello again,
    I am really sorry but I can't come up with any good solution for that right now. I will definitely look at this more in-depth in the weekend and hopefully find a suitable solution for you. I may even need to ditch the current avoidance implementation and come up with something better as a whole.
    Thank you.
     
  15. ciaravoh

    ciaravoh

    Joined:
    Dec 16, 2009
    Posts:
    252
    ok. Thank you for your help. I think I will find another way to implement this process.
     
    nuverian likes this.
  16. smasters654

    smasters654

    Joined:
    Dec 20, 2013
    Posts:
    46
    Hello @nuverian,

    I am having a performance problem with PolyNav and I have a guess as to where it is coming from but I was wondering if you had any suggestions.

    In my attached screenshots I am showing profiler spikes with polynav. I have a randomly generated dungeon with some enemies that have the polynav agent component. When my player is not within a certain small distance of the enemies, their navigation and other AI is turned off.

    This works great for smaller dungeons, but when I increase the dungeon length, the profiler will show these spikes from polynav(in the screenshot), even when it is only 1 or 2 agents moving at one time. My guess is that all of the dungeon's polynav obstacles are being checked by the agents when ever they calculate their move, which may be causing the spikes and framerate drops. Each room in the dungeon has about 2 to 4 polynav obstacles depending on if the doors are blocked.

    Is there any way to increase the performance with the information I have here? Or is there something else I am missing?

    Thanks!
    PolyNavScreen01.png PolynavQuestion02.png
     
  17. Deleted User

    Deleted User

    Guest

    Hey everyone, just had a quick query regarding 'weighted' paths. Is it possible to achieve this with PolyNav or is there some way you can just dynamically set a new obstacle for just an individual agent?

    I've got some enemies that basically follow you over traps, which is totally fine. But as a nice to have I'm wondering if I can just make a few of them in to cowards. :p

    Cheers and keep up the great work!
     
  18. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    I have replied to your email.
    Thanks.

    Hello and thanks for looking at PolyNav :)
    Unfortunately though, having different obstacles for different agents is not possible in PolyNav, and the same navigation map is used for all agents equally the same.
    For the example you posted though, you can however maybe achieve it by checking whether or not the trap is along the found path (by sampling the path every x units and making a distance check to the trap, or with raycasts), and if it is not, make the agent traverse the path, otherwise, do something different (probably smarter) than falling in the trap :_)
    If you want any code help with this proposed solution let me know.
    Thanks.
     
  19. grogshotgames

    grogshotgames

    Joined:
    Aug 6, 2015
    Posts:
    77
    Hi nuverian!
    I was able to succesfully change the avoidance center offset between agents thanks to the code that you sent me, but this doesn't seem to work for obstacles avoidance.
    I guess this is because you only used the avoidanceCenterOffset inside LookAhead method and not in the rest of the code.

    Is it possible to add the same offset so it affects obstacles as well?
     
  20. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    Hey,
    Do you mean like using this offset in a way as to modify the pivot position of the agent?
     
  21. grogshotgames

    grogshotgames

    Joined:
    Aug 6, 2015
    Posts:
    77
    Yep. That's it.
     
  22. Deleted User

    Deleted User

    Guest

    Hi Nuverian!
    Thanks very much, I'll give that a try. Sorry for the late reply! I figure like you say it shouldn't be too much of an issue to just make the agent favour a different path 'if' there's an alternate route nearby. Pretty impressive what you can achieve with the component when you put your mind to it.

    Cheers :)
     
  23. grogshotgames

    grogshotgames

    Joined:
    Aug 6, 2015
    Posts:
    77
  24. shinJH

    shinJH

    Joined:
    Oct 23, 2013
    Posts:
    2
    Hi.
    This is the best library to 2d Nav.Thank you.
    But, There is a problem with isProcessingPath.

    PolyNav2D Class
    -----

    voidOnEnable(){
    _current=this;
    isProcessingPath=false; //reset
    }
     
  25. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    Hey,
    You can actually open up PolyNav.cs and replace the property named position with this code:
    Code (CSharp):
    1.     ///The position of the agent
    2.     public Vector2 position{
    3.         get {return transform.position + (Vector3)centerOffset;}
    4.         set {transform.position = new Vector3(value.x, value.y, transform.position.z) - (Vector3)centerOffset;}
    5.     }
    Just please remember to also remove the centerOffset additions we made in LookAhead method in our previous discussions.
    Let me know if that works for you.
    Thanks.


    Hey,
    Thanks! I am very glad you like PolyNav :)
    Can you please explain the problem a bit more?
    Is this code you posted, your suggested solution to that problem?

    Let me know.
    Thanks.
     
  26. banksazero

    banksazero

    Joined:
    May 8, 2015
    Posts:
    77
    Hi
    nuverian

    I have some question about polynav again.
    1.Are you have any full document or any more guide about OndestinationReach OnDestinationInvalid(I want to use this like if(agent.OnDestinationInvalid{//Do something }) ?
    I try to use that but I'm don't know how to use until now.(sorry I'm not programmer T-T)
    2.Are you have any suggestion about recommend method (I only know about SetDestination)
    3.I would like to set my agents not have acceleration and deceleration is this can do or I have only way is change this as high value(I want my agents respond speed instant) and I would to know about mass too are this have any problem about instant speed ?
    4.Have any suggestion about performance? (I only need my agents navigation itself and know target rotation not rotation only target rotation)

    If you don't understand anything please tell me.(for me hard to write sentence =))
    ThankYou
     
  27. shinJH

    shinJH

    Joined:
    Oct 23, 2013
    Posts:
    2
    When PolyNav Inactive, AStar CalculatePath Coroutine stops.
    At this time isProcessingPath is true, characters can not find the characters.

    As a solution -------
    voidOnEnable(){
    _current=this;
    isProcessingPath=false; //reset
    }
     
  28. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    Hello!

    Sorry for the late reply, but I missed your post. Please let me address your questions:

    1) OnDestinationReached and OnDestinationInvalid are c# events. Events are used by subscribing to them to get a callback (eg call a function) when they are raised. Here is one way of using those events for example:
    Code (CSharp):
    1. public class Example : MonoBehaviour{
    2.  
    3.     private PolyNavAgent agent;
    4.  
    5.     void Awake(){
    6.         agent = GetComponent<PolyNavAgent>();
    7.     }
    8.  
    9.     void OnEnable(){
    10.         agent.OnDestinationReached += DestinationReached;
    11.         agent.OnDestinationInvalid += DestinationInvalid;
    12.     }
    13.  
    14.     void DestinationReached(){
    15.         //do something
    16.     }
    17.  
    18.     void DestinationInvalid(){
    19.         //do something
    20.     }
    21. }
    In the above example, we subscribe the method named DestinationReached to the OnDestinationReached event. When the even is raised, DestinationReached will be called (Same thing happens for OnDestinationInvalid event.).

    The included PatrolRandomWayPoints example scripts also makes use of those events if you want to check it out.
    Let me know if the above helps.

    Another thing you can do to check if the destination is valid or not, is to check the SetDestination method itself when you call if. SetDestination will return false if the destination is invalid and true if it is valid. For example:
    Code (CSharp):
    1.     void Update(){
    2.  
    3.         if (Input.GetButtonDown("Fire1")){
    4.             if (agent.SetDestination(targetPosition)){
    5.                 //valid destination and going there
    6.             } else {
    7.                 //invalid destination
    8.             }
    9.         }
    10.     }

    2) SetDestination is the most important method of course, but the PolyNavAgent has a number of useful properties you might also want to use, like remainingDistance, movingDirection, currentSpeed and so on. These are fully commented by the way.

    3) If you want to have the agents reach full speed instantly without acceleration (or deceleration), please try setting Mass to 1, Acceleration Rate to something high like 10 and Deceleration Rate to 0.

    4) If you want to save a bit of performance, you can try disabling the options Repath, Restrict and Closer Point On Invalid unless of course you need them :)

    Let me know if the above works for you and sorry in advance if I did not understand some of the questions.
    Thanks!


    Hey,
    Thanks for the explanation and fix :)
     
  29. banksazero

    banksazero

    Joined:
    May 8, 2015
    Posts:
    77
    Hi Nuverian
    I have try to add 2 PolyNav2D map(for separate rooms) but see when I add another polynav2d look like the agent ignore that.
    Could I use multiple PolyNav2D for each room ?

    Thank you
     
  30. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    Hello and very sorry for the late reply. (totally missed the notification for this post)
    Unfortunately only one PolyNav2D map is supported to exist in the scene.
    You can though have the polygon of that one PolyNav2D map be as big as you require to contain both the rooms and then you can create NavObstacles to actually separate the rooms with one another.
    Apologies for the late reply once again.
     
  31. banksazero

    banksazero

    Joined:
    May 8, 2015
    Posts:
    77
    Hi Nuverian
    I again I have 2 question
    1.Can I check agent path is straight (I would like to add a dash action (when the path straight the AI will dash 1 time))
    I think this can check path point (pick 3 points Start middle end point) then compare slope.
    or you have any suggestion please let me know.
    2.I would like to see straight path to a invalid point (Please see figures below).Can this happen
    the black line is what I would like to see.

    Thank you.
     

    Attached Files:

  32. grogshotgames

    grogshotgames

    Joined:
    Aug 6, 2015
    Posts:
    77
    It's actually really easy to modify polynav to make it work with more than one polynav2d. You just need some code modifications but it works
     
  33. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    Hell Piako,

    Sorry for the late reply (I was on a trip away from office).
    Please let me address your questions:

    1) If you mean checking if a straight line from point A to point B, would hit an obstacle, then yes, you can do that by using the method called CheckLOS (LOS for Line Of Sight), like for example:
    PolyNav.current.CheckLOS(pointA, pointB).
    This will return true if nothing is hit, and false if something is hit.
    Let me know if that is what you were indeed after.

    2) Can you please explain a bit more about this second question? Is this a question about how to visualize the line?

    Thank you.

    Hey,
    Yes, that is indeed something that is not that hard to do, and I would like to actually do it once I have some time to work on PolyNav again.
    Thanks.
     
  34. banksazero

    banksazero

    Joined:
    May 8, 2015
    Posts:
    77
    Thank you
    I have test the LOS it really work great if I know this before maybe I didn't buy a asset.

    My second question
    Now I use set velocity for dash [dash by angle ,speed and time when hit a collider stop]
    before this I don't use this Nav for dash because it require point before setdestination() and sometimes my dash point is invalid for PolyNav2D but I would like to ask you if I set invalid point how to I force the agent same direction [I see when the point is invalid the agent try to go to nearest point with another direction].
    in first figure show target is in invalid point the agent try to go nearest point but that is not straight line.
    in second figure the black line is the path I want.

    I also have a extra question.
    How I set the agent do not get near obstacles too much [I have try avoid radius it look like be unrelated with obstacles]


    Please let me know if I wrote something wrong or you want more details.

    Sorry for my writing I don't use English as primary but I try to learn.
     

    Attached Files:

  35. gtaharaedmonds

    gtaharaedmonds

    Joined:
    Sep 12, 2016
    Posts:
    3
    I got this asset a while back for a stealth game I'm making. Is there any way to test the distance to a location instantly? I'm currently using a workaround by just setting the destination. But there is an issue where it takes 1 frame after setting the destination for remainingDistance to update. What I mean is the same frame you set the destination, remainingDistnance is 0 even when it shouldn't be. Then the next frame it updates to the correct value. This just leads to a lot of buggyness so I'm just wondering how I can get the distance to a point instantly? I hope this made sense. Thanks.
     
  36. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    I am really sorry, but apparently I missed your post completely!
    For your first question, since NavObstacles are also 2DColliders, maybe what you really are after here is doing a 2D raycast in the direction you required and then use the hit.point of the RaycastHit2D returned?

    Regarding keeping distance from obstacles, this distance can be set by the "Radius" property in the PolyNav2D inspector. Please note that this is not per-agent, but rather applies to all agents the same.

    Let me know if these work for you.
    Once again, I am very sorry for missing your post!

    Hey,
    This will require a small change in the source code. Please open up AStar.cs and move line #58 'yield return null', right after the "callback" (instead of before like it currently is).
    Let me know if this will work for you.
    Thanks!
     
  37. firestoke

    firestoke

    Joined:
    Oct 21, 2015
    Posts:
    13
    Hi Developer,

    I have met a problem today.
    If I set a GameObject with PolyNavAgent and PolyNavObstacle both. The game object will keep "JUMPING" when in runtime. Can you add the feature to avoid agent checking self's PolyNavObstacle component?

    I must do so, because that I have many characters controlled by AI in one scene. A character object should keep a distance away from the other characters. Thus, I add agent and obstacle both in the character game object.

    Thanks!
    David
     
  38. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084

    Hello David,
    You should really not use NavObstacle along with NavAgent, because then whenever the agent is moving, the navigation map will be regenerated and this will cause performance issues :)
    If you want agents to avoid each other, please use the "Avoid Radius" property on the NavAgent inspector. All agents with an Avoid Radius higher than zero, will try to avoid each other.

    Thanks!
     
  39. firestoke

    firestoke

    Joined:
    Oct 21, 2015
    Posts:
    13
    Hi, Thanks for your reply.
    I have tried the way you suggest. But the characters didn't avoid each other. I don't know why.

    1. two characters in the scene. the box2d collider is on the foot area.
    2. the component setting. I did set the Avoid Radius as 1.
    3. I make the goblin move to the position on the bottom of anther character. But the goblin will still pass through it.

    any idea ?

    BR,
    David
     

    Attached Files:

    • 1.png
      1.png
      File size:
      39.5 KB
      Views:
      818
    • 2.png
      2.png
      File size:
      48 KB
      Views:
      763
    • 3.png
      3.png
      File size:
      33.5 KB
      Views:
      774
    Last edited: Mar 25, 2017
  40. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    Hello again,
    Sorry for the late reply, but I missed your post. Can you please contact me to "support_AT_paradoxnotion.com" so that we resolve this issue. If possible at all for you, please send me your project (or another small reproduction) to check it out. If so, that would be really great.
    Thank you!
     
  41. stoomm

    stoomm

    Joined:
    Apr 7, 2013
    Posts:
    15
    Hello Nuverian,

    I've a problem with polynav. For a game, I need sometimes to make a scale.x = -1 on polynav.
    In this case, EdgeCloserPoint seems to doesn't work.

    For testing, on the demo scene in Polynav :

    Test ok :

    - spaceship_ClickToMove => Closer point on invalid = Yes
    - Launch

    When you click outside the polynav, spaceship goes to the closer point.

    Test ko :
    - spaceship_ClickToMove => Closer point on invalid = Yes
    - Polynav2D => Scale X = -1
    - Launch

    When you click outside the polynav, nothing happens.

    Any idea or patch ?

    Thanks a lot ;)
     
    Last edited: Apr 7, 2017
  42. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084

    Hello!

    I am sorry, but I am not sure how to replicated the issue :)
    I have just re-checked to confirm, but scaling the agent to x = -1 (or any other value), does not really affect it's pathfinding, neither the CloserPointOnInvalid option turned on. (it still finds and navigates to the closer point on the edge when I click outside the navigation area).

    Can you please provide a bit more details?
    Thanks!
     
  43. xiaolei000

    xiaolei000

    Joined:
    Aug 4, 2016
    Posts:
    1
    Hi nuverian.

    I have a performance issue with GenerateMap method.
    In my game, i have a very large map, and there are many items with PolyNavObstacle attach to them. And some of the items are breakable, when i break an item, the GenerateMap method in PolyNav2D will be executed, because of the large number of Nodes, this opration takes too much time. Is there any solutions except reducing items?
    (I add a lable to disply number of PolyNavObstacle)
    polynav2d.png polynav2d1.png
    Thanks and sorry for my poor English.
     
    Last edited: Apr 11, 2017
  44. jebediahh

    jebediahh

    Joined:
    Feb 20, 2017
    Posts:
    26
    Hello - I'm having a bit of trouble getting the details correct when trying to add obstacles at run time. I've placed a PolyNav2D gameobject in the scene in the editor. Now I'm attempting to add obstacles in code. I'm making guesses as to how to actually do this and it's not working out..Would it be possible for you to please post a code snippet that will create an obstacle at run time?
     
  45. stoomm

    stoomm

    Joined:
    Apr 7, 2013
    Posts:
    15
    Hi Nuvarian,

    Thanks for your reply.

    The problème is not with scaling the agent, but with scaling the polynav2d :

    Test ko :
    - spaceship_ClickToMove => Closer point on invalid = Yes
    - @Polynav2D (not the spaceship or agent)=> Scale X = -1
    - Launch

    When you click outside the polynav, nothing happens.

    Thanks ;)
     
  46. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    Hello,
    Unfortunately the GenerateMap method is not really meant for dynamic usage such as regenerating the map for dynamic obstacles since it takes time to perform. The runtime generation is really meant for allowing the creation of the map for procedural levels for example (rather than dynamic ones).
    I could possibly make a new method like "GenerateMapAsync" to generate the map without a noticeable framedrop, even though this means that the change will not be instant and the previous map will be used until the new one is ready after a "GenerateMapAsync" call.
    Let me know if that is something you will find useful.
    Thanks.

    Ahh. I thought you were referring the the PolyNavAgent, rather that the PolyNav2D object itself :)
    Sorry, but scaling the whole PolyNav2D object itself negatively, is not something I've taken into account.
    Basically when you negate the scale the polygons that make up the map are inverted as well.
    Is this scaling something you do once, or it changes during game?
    Let me know.
    Thanks.
     
  47. Elendow

    Elendow

    Joined:
    Apr 9, 2014
    Posts:
    87
    Hi,

    I'm having some trouble too with removing obstacles on runtime. Same case as xiaolei000. The GenerateMapAsync could work as a workaround.

    Theres a chance that we get someday the multiple PolyNav2D maps on one scene? My game would fit perfectly with that because is "room" based and multiple little maps would work better than a huge one. That also would help with the dynamic obstacles (less map, less o regenerate).

    Thanks for your work and your asset, best 2D NavMesh plugin so far!

    Cheers!
     
  48. nuverian

    nuverian

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

    Thanks a lot for your positive feedback!
    Yes. Multiple maps are already implemented and as soon as I have GenerateMapAsync in there, the new version will be submitted :)
    Thanks again!
     
  49. Doobyman168

    Doobyman168

    Joined:
    Feb 21, 2014
    Posts:
    14
    Hi Nuverian,

    I'm having a problem with multiple agents not avoiding each other. My game is an RTS style, and if I move two or more agents to the same target destination a want them to huddle around it, but at the moment they simply overlap. I have done as suggested earlier in the thread and set their stopping distance to higher than their avoidance radius.

    Thanks for any help you can give!
     
  50. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,084
    Hello,
    Can you please try increasing the Look Ahead Distance and let me know? Ideally it should be higher than the Avoidance Radius.
    Thanks.