Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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,
    Is it possible to PM me a small porject link so that I can take a look? I can't seem to find the cause and this has never been reported again before.

    Thanks!

    Hello,
    Unfortunately PolyNav is not suited for platform games such as this, where there are different walking heights and possibly gravity. :)
     
  2. Milo_del_mal

    Milo_del_mal

    Joined:
    Jan 27, 2013
    Posts:
    43

    Thank you for the honest response. I am working on a solution at the moment.
     
  3. Zsquare.co

    Zsquare.co

    Joined:
    Nov 2, 2015
    Posts:
    6
    Hello,
    In some ways I do not know if you can show which parts to you.
    You'll want to check the audit section will teach you how to share and.
     
  4. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Hi,
    So far this asset work as I need to except for one instance. I tried figuring this out but couldn't.

    Code (CSharp):
    1. agent.SetDestination(new Vector2(0,0));
    Why am I not able to set the initial destination to 0,0?

    If I were to set the initial destination to let's say 10,10 and then while the game is running, if I were to change the destination to 0,0 then it works.

    It appears that when you set the initial (1st frame?) destination to vector2.zero it doesn't work. Simple doesn't move. No errors.

    Thank you!
     
  5. Zsquare.co

    Zsquare.co

    Joined:
    Nov 2, 2015
    Posts:
    6
    One exists in PolyNav2D features?
    Objects that do not push each other object, do not overlap
    Ability to find the path.

    For example, like the movements of minion in the League of Legends.

    Thank you.
     
  6. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey,
    Please open up the PolyNavAgent.cs script and make sure the Awake method looks like this:
    Code (CSharp):
    1.     void Awake(){
    2.         primeGoal = transform.position;
    3.         _transform = transform;
    4.     }
    Let me know :)

    Thanks.

    Hello,
    If you mean a feature where characters push each other and avoid each other, then yes, there is a simply avoidance feature implemented :)
    Is that what you mean?
    Cheers
     
  7. Zsquare.co

    Zsquare.co

    Joined:
    Nov 2, 2015
    Posts:
    6
    Yes.
    But I want to increase the detour range of objects.
    Because my object is to want to move like a minion of the League of Legends.
    Please let the solution.

    Thanks.
     
  8. Korathas

    Korathas

    Joined:
    Dec 4, 2015
    Posts:
    4
    Hi nuverian,

    I bought your asset a while ago but only just got around to using it. I see from the changelog you've made a lot of really good improvements! Amazing work!

    I'll admit I'm mostly here to inquire about a small null reference error I get when using the ClickToMove script. More specifically line 20:
    Code (csharp):
    1. agent.SetDestination(Camera.main.ScreenToWorldPoint(Input.mousePosition));
    It throws a null reference exception, which is weird because I'm sure the agent object has the PolyNavAgent component, my @PolyNav2D gameobject exists as well, all properly set up... It leads me to think it could be SetDestination itself? I tried a bit of debugging, but I don't know. It didn't really work out, as you can see. In addition to that, MoveBetween works fine on both my own scene and your demo scene. What's even stranger is that ClickToMove does seem to work in said demo scene. I'm at a loss. Any help would be greatly appreciated!

    (Also I have this weird bug with MoveBetween sometimes where random agents get stuck on startup.They will refuse to move at all whatsoever.)

    Thanks in advance :)
     
    Last edited: Dec 5, 2015
  9. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello again,
    You can increase the avoid radius per agent from the PolyNavAgent inspector.
    I am sorry if I fail to understand your question. If so, please try to rephrase and I will try again :)
    Thanks.

    Hello there,

    Thanks! I'm glad you like PolyNav, but please don't attach the whole asset in public (or any other paid asset for that matter) :) Feel free to PM me a link instead next time. No worries though!

    So, I've checked the project but I don't get any null reference exception, or any other problem, except from the fact that the MoveTo script is not working properly as it is now, because you have to set the camera to be Orthographic rather than Perspective in it's inspector. Once you do that, the ClickToMove script will work properly.
    But, let me know if it doesn't or if you encounter any issue.

    Cheers
     
  10. Korathas

    Korathas

    Joined:
    Dec 4, 2015
    Posts:
    4
    Hi again!

    First of all, my very sincere apologies for sharing it in public earlier. I'd been on an all-nighter.
    In any case I'm an idiot. For some reason in my sleepless state I managed to untag the camera as the main camera... So that's how that happened. (In addition you're also right about having to use orthographic... Sigh.)

    Thank you very much. I made sure I left a good review in the asset store.
     
    Last edited: Dec 6, 2015
  11. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Give yourself some credit nuverian ;) I have a point-n-click 2D platformer working just fine using polynav2d! It still has some hiccups here and there but that's more on my end than yours.
     
  12. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey,
    Don't worry about it. Also thanks for your review! I really appreciate it and I'm glad it works for you now.
    I'm also doing weird stuff when I'm sleepless :)
    Let me know if you come across anything I can help you with.

    Thanks!

    Hey,
    Great! Glad to hear that you are finishing a game using polynav :)
    Share your game with us when you want to :)

    Cheers!
     
  13. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    Sorry for the choppiness of the video as this is just a quick example.



    The character controller is my own and was originally designed to simply move left or right to follow the cursor. However the only way I could display an accurate hovering 'destination marker' as well as use this system for AI-controlled entities was to adapt it to use some kind of path finding. I use a modified version of polynav that a) allows me to click within polygons and finds the nearest open space outside of them b) casts downward and re-positions the final node of the path so that it is located on the top-side of a surface and c) is highly optimaized (compared to an earlier version anyway). You'll notice that when i hold the mouse button down quite a few paths are calculated. I throttled it to something around 15 per second to help avoid bogging down mobile devices.

    One the path is determined a sort of AI makes the player's character follow the path as best as it can. In the case of small ledges it simply detects them with a few raycasts and leaps over them. When more complicated situations arise I have a navigation-hint system that kicks in to help the entity know when to jump / re-route to a different location / re-path / etc... As you can see it still has some issues getting around more complicated geometry but that's a deficiency with my AI and not polynav2D.
     
  14. Zsquare.co

    Zsquare.co

    Joined:
    Nov 2, 2015
    Posts:
    6
    Hellow.
    I'm sorry to bother you every time.

    I want this situation.



    Pictures like,
    LittleMonsters(dimik) that want to go back in the direction of the arrow.



    Ps. Every time I saw this communication is Korean's hard.:(
    Every time you get the help of Google Translator.
    If I'm rude if I will apologize.:)
     
  15. nuverian

    nuverian

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

    It's very cool that you've managed to modify PolyNav into a 2D platformer pathfindind and yeah, even though it needs some more work for the jumping part, it seems that you are almost there. Well done :)
    Also thanks for sharing how you did it. It's interesting and maybe more people could make use of this.

    Cheers!

    Hey,
    Don't worry about it. You are not rude at all :)
    What you want shown in the image, is unfortunately not really possible out of the box. The character will instead try to move towards it's goal, passing through the other character and not around.
    I am sorry if this doesn't help you :/
    Let me know
     
  16. Nihilbug

    Nihilbug

    Joined:
    Apr 16, 2014
    Posts:
    1
    Question. I've been looking at this and it looks very good but I was wondering if there is a way to configure the grid via script? I'm working on procedurally generated levels and am trying to find a good solution for pathfinding that I can also use to dynamically create grids.
     
  17. Siegfried

    Siegfried

    Joined:
    Dec 10, 2012
    Posts:
    8
    Hello,
    does it work with Unity 5.1.x/5.2.x ?

    Is it possible to have other moving objects on the scene (ie other actors walking around) ?
     
    Last edited: Dec 12, 2015
  18. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    I am very sorry! I missed your post! :(
    PolyNav does not work with grids, but rather with polygons. So if you are looking for a grid based solution this might not fit your needs. Having said that, yes, it is possible to set the polygons in runtime through code if you need so. The new version around the corner will provide some more usefull methods for doing this easier.

    Cheers!

    Hey,
    Yes, it works with Unity 5.x fine. You will be prompted to update the scripts though. In any case I will also commit the new version for Unity 5.3.
    Regarding your 2nd question, I am not really sure what you mean :). Can you please clarify?
    Thanks!
     
  19. foxifi

    foxifi

    Joined:
    Dec 20, 2015
    Posts:
    55
    Hi nuverian,

    got Poly|Nav pretty recently and have been watching this forum mainly to see if you have any updates on having multiple PolyNav walkable areas in a scene, any info on that? I think it would be perfect for "cells" of larger game worlds that would be less performance heavy. Right now my game isn't nearly large enough to require this though.

    I wanted to ask a few more questions though, for instance, several users had asked about other player avoidance and things of that nature. Since you already covered moving object avoidance for when multiple objects are in motion using PolyNav, would a solution for solving these objects when they have stopped moving be simply enabling the PolyNav Obstacle component only when they become motionless, and then deactivating it again when the object begins moving again? I realize this might be an issue with updating the polynav walkable area, but it seems only if the object is moving and then stopping again very rapidly.

    Also, mainly, my game is top-down and currently I move the player in 8 directions. While having these directions looks pretty good still with no constraints to movement with polynav, would it be possible to restrict PolyNav's path to be more like my 8-direction movement? For instance, if the target is somewhere to the right and above the player, instead of moving directly to the point in a straight line that may have a steeper angle than 45 degrees to the player, move at 45 degrees until directly beneath the target if possible, and then move directly upwards to the target?

    I'm sorry for asking if its hard to understand, and I realize PolyNav is designed to be used with more fluid movement, but I just wanted to ask about it incase you could provide some information on how to go about modifying things to accomplish this.

    Thank you, and regardless I love the asset and can't wait for future updates, it works beautifully and was very easy to integrate into my project.
     
  20. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello and sorry for the late reply.
    I am glad you like polynav and is helpful thus far to your project :)

    Multiple PolyNav areas unfortunately have not made it yet because I didn't have time to work on updating polynav yet, something that will happen with the comming of the new year though and version 2.0.

    Restricting the movement of the objects to be made into 8 directions is quite difficult to implement to a system like polynav, and would result in more problems than it would solve in my opinion. Regardless, one way that it could probably be implemented, would be to alter the found Vector2[] path in a way that would resemble the preferred path the agent would take, thus be made as post-process to the path.

    Regarding your first question, unfortunately, I am not sure I understand what you mean :)
    Agents will avoid each other even when they are not moving. Can you please clarify?

    Thanks and happy holidays!
     
  21. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    614
    so lets say i have 1 polynav in my game on MOBILE.

    I constantly move 1 single obstacle at a time to block the pathway of a few agents.

    How will performance be?

    The navmesh won't be huge, maybe 800x1280 pixels or so.
     
  22. nuverian

    nuverian

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

    The size of the map does not matter. What matters is the number of obstacles and as such the nav corner points that will be created due to this. Let me know of an estimation and I will be able to provide a better answer :)

    Thanks
     
  23. MrBarragan

    MrBarragan

    Joined:
    Dec 9, 2012
    Posts:
    2
    Hello Nuverian. I'm having an issue with polynav and I was hoping you could help me fix it.

    I've added custom code so the editor shows the nodes as red squares for debugging purposes. Once I did that I realized why my guys were getting stuck. Polynav appears to be routing agents through obstacles in my case. Please see the screenshot attached:
    Capture.PNG

    As you can see the white agent path is being routed through the obstacle polygon. The red squares show that the correct nodes are being created around the obstacle but it's somehow disregarding that bottom right node.

    Any ideas? Please let me know if you need additional info.

    Thanks in advance.
     
  24. MrBarragan

    MrBarragan

    Joined:
    Dec 9, 2012
    Posts:
    2
    After much debugging I solved my own problem. It appears that when using a box collider (4 points) this happens. Even when I changed the obstacle collider to be a polygon but removed a point to make it a square this would happen.

    It works fine when I make a square with a 5 point polygon collider.... Not sure why but the "checkLOS" function appears to work much better with true 5 point polygons than with boxes of 4 points.

    Hopes this helps someone sometime.
     
  25. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    That's a really weird issue cause I can't reproduce it here no matter what.
    Is it possible at all for you to send me a reproduction mini project to check this out?
    support@paradoxnotion.com

    Thanks!
     
  26. Phuzz

    Phuzz

    Joined:
    Mar 31, 2014
    Posts:
    48
    Hello,

    First, thank you for the great path-finding solution.

    I am encountering a small problem, whenever I destroy an object containing the Obstacle component I get a huge spike in the profiler and it freezes everything for 1 second which also causes a frame rate drop ofcorse. I get a "PolyNav Late update 96%" on the profiler. I am using playmaker for my actions. Thank you.
     
  27. calebc01

    calebc01

    Joined:
    Jul 21, 2015
    Posts:
    62
    Is there a way to have the path planner account for the size of the nav agent? I have various objects of differing sizes, and sometimes the path taken causes the objects to collide with the nav obstacle.

    Also, I have my own navigation code that utilizes Unity's 2d physics engine via the RigidBody2D class. Nominally, I'd like to use PolyNav to generate a list of points in the path, and then follow the path using my own control code. I can dive into the code and figure out how to do it myself, but I'm wondering if that option is available.

    Cheers!
     
  28. calebc01

    calebc01

    Joined:
    Jul 21, 2015
    Posts:
    62
    In answer to myself...

    It doesn't appear that nav agent sizes are considered at all, so you need to make sure that your model center (or sprite center) is on the center of the collider, or on the center of mass of the model if no collider is used. Then set the PolyNav2D radius high enough to accommodate your largest object. The smaller objects don't get to be closer, but it otherwise works out.

    I also ended up copying the PolyNavAgent class and renaming it to RBPolyNavAgent, for RigidBody. I then removed the LateUpdate() function call (actually, I just renamed it), and I implemented my own force-based point navigation code in a FixedUpdate() function call. I copied the code I needed from LateUpdate() and ignored the rest. Code shown below:

    Code (csharp):
    1.  
    2.     // Physics simulation
    3.     void FixedUpdate()
    4.     {
    5.         if (polyNav == null)
    6.             return;
    7.  
    8.         Vector2 position = tf.position;
    9.         Vector2 primePositionError = primeGoal - position;
    10.         Vector2 positionError = nextPoint - position;
    11.         Vector2 velocity = rb.velocity;
    12.         float speed = velocity.magnitude;
    13.  
    14.         float primePositionErrorMagnitude = primePositionError.magnitude;
    15.    
    16.         // If we have a path, check to see if we need to switch waypoints
    17.         if (hasPath)
    18.         {
    19.             float proximity = (activePath[activePath.Count - 1] == nextPoint) ? positionErrorThreshold : 0.05f;
    20.             if ((position - nextPoint).sqrMagnitude <= proximity)
    21.             {
    22.                 activePath.RemoveAt(0);
    23.  
    24.                 //if it was last point, means the path is complete and no longer have an active path.
    25.                 if (!hasPath)
    26.                 {
    27.                     OnArrived();
    28.                     return;
    29.                 }
    30.                 else
    31.                 {
    32.                     if (repath)
    33.                     {
    34.                         //repath after a point is reached
    35.                         Repath();
    36.                     }
    37.  
    38.                     if (OnNavigationPointReached != null)
    39.                         OnNavigationPointReached(position);
    40.                 }
    41.             }
    42.         }
    43.  
    44.         if (primePositionErrorMagnitude >= positionErrorThreshold)
    45.         {
    46.             float targetSpeed = Mathf.Min(primePositionErrorMagnitude * positionErrorToTargetSpeedScale, maxSpeed);
    47.  
    48.             Vector2 targetVelocity = positionError.normalized * targetSpeed;
    49.             Vector2 velocityError = targetVelocity - velocity;
    50.  
    51.             Vector2 force = accelerationScaleFactor * (velocityError);
    52.  
    53.             rb.AddForce(force, ForceMode2D.Force);
    54.         }
    55.         else if (speed >= Mathf.Epsilon)
    56.         {
    57.             rb.velocity = Vector2.zero;
    58.         }
    59.     }
    60.  
    With this code, the PolyNav system uses Unity's 2D physics system to move objects around instead of just changing the transform position. So other objects can push your nav agents around even if they don't use PolyNav. Also, once your agent arrives, if anything pushes it off its desired position, it will try to get back on.

    Another "feature" of the above is that when your nav agent gets close to the final position (the "prime position" in code), its velocity will scale linearly down to zero as it approaches the goal. So its velocity doesn't just suddenly stop, it gradually slows.
     
    Last edited: Jan 26, 2016
    TyrannicGoat and Greenwar like this.
  29. Greenwar

    Greenwar

    Joined:
    Oct 11, 2014
    Posts:
    54
    I'm in need of a physics based movement solution as well, and your code works wonders.
    I modified it slightly to allow for the rigidbodies to look ahead using angular velocity (i've found that addforce and direct translate rotation manipulation don't go too well hand in hand). I can post it here if anyone is interested.

    The only drawback with colliders is that agents will get stuck. A lot. In most ways imaginable...

    I'm not sure how to efficiently fix this yet.
     
  30. Fernandxor

    Fernandxor

    Joined:
    Oct 13, 2014
    Posts:
    23
    Hi nuverian,

    I'm using polynav2D inside my Point&Click Graphic Adventure. It works pretty well for that meaning, but I need to simulate some fake perspective, where my characters walk slower to the background (because of the perspective itself). By walking to the background, I mean when my characters are facing "up". In a top-view game or an isometric one you don't care about speed because it's always the same, but here is not the case (in fact, my characters resize themselves using the Y coordinate). Do you have any clue of how can I achieve this behaviour?

    Greetings!
     
  31. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    You can do this manually.
     
  32. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    Thanks as well :)
    Whenever you destroy/disable/enable/move an PolyNavObstacle object, the navigation map is regenerated and that really is slow especialy if you have a lot of obstacles. If you don't want to regenerate the map, you can check off the option "Regenerate On Change" on the PolyNav2D inspector.
    The regeneration possible here, is really not ment for realtime dynamic changes, but rather for a way to proceduraly generate the map, or modify it in some very infrequent and not dynamic in nature way.

    Thanks!

    Hey,
    That's prety cool! I can add a mode toggle in the inspector to change between normal and rigidbody based movement in the next update. Thanks for sharing your code :)
    Cheers!

    Hello,

    Here is a quick code to do what you are after :):
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class ChangeSpeedOnDepth : MonoBehaviour {
    4.  
    5.     //when y = 0, speed = 5
    6.     public float minY = 0;
    7.     public float maxSpeed = 5;
    8.  
    9.     //when y = 5, speed = 1
    10.     public float maxY = 5;
    11.     public float minSpeed = 1;
    12.  
    13.     private PolyNavAgent _agent;
    14.     private PolyNavAgent agent{
    15.         get {return _agent != null? _agent : _agent = GetComponent<PolyNavAgent>();}
    16.     }
    17.  
    18.     void Update () {
    19.         var normalizedY = Mathf.InverseLerp(minY, maxY, transform.position.y);
    20.         agent.maxSpeed = Mathf.Lerp(maxSpeed, minSpeed, normalizedY);
    21.     }
    22. }
    23.  
    Cheers!
     
  33. calebc01

    calebc01

    Joined:
    Jul 21, 2015
    Posts:
    62
    PolyNav is working really great for me! The code is well-factored and well-documented, and it's a real pleasure to work with.

    I'd love to see "path cost" polygons added as a feature. Right now, you can add obstacles and nav agents. But it would be incredibly awesome if you could put a polygon onto the board that isn't an obstacle, per-se, but that has a higher path cost than an empty space.

    The use-case might, for example, allow enemy agents to avoid areas where the player built a destructable wall - sure, they can attack the wall to get through, but it would be better to roll through Belgium... :)
     
    nuverian and johanneskopf like this.
  34. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    Thanks! I am glad you like PolyNav :)
    I like your suggestion. I will take a look at how to implement path cost for polygons. It will be a bit tricky since there is no underlying grid being used.

    Thanks
     
  35. theredace

    theredace

    Joined:
    May 30, 2013
    Posts:
    7
    Nuverian, thanks for the awesome tool! I've been playing around with it off and on for a while prepping for a game I'm just now starting on and had a few questions:

    1. My game uses pretty large scenes (scrolling camera), so I'm concerned about overall performance. I know that using box colliders for the NavObstacles is easier to process than polygon colliders, but with an isometric game it's tough to make accurate collision areas using box colliders. If I use a box collider on a NavObstacle, but I rotate the collider in 3D space, is it still processing it like a box collider or have I essentially made it into a polygon collider because it's no longer an AABB object in 2D space? Just trying to figure out the cheapest colliders I can add to each of my scene obstacles for best performance. If I have to use polygon colliders, how many would you estimate in a scene before we're hitting performance issues? Or perhaps the better question is how many polygon collider vertices in a scene is too many?

    2. This is not really a specific Poly|Nav question, so I throw this out to anyone who has any thoughts on it... I'm using an orthographic camera and handling layering in the game by setting the 'order in layer' according to the object's Y-coordinate, so that objects lower on screen appear in front of higher objects. I only do this in the editor, and at runtime only the character himself actually changes its 'order in layer' to move in front/behind objects. This seems like a common method and works quite well. The problem I'm running into is with diagonal objects where the position of the pivot point can make it so that the character position is technically lower than the object's pivot point position, so the character appears in front, but the character actually should be behind. For example, imagine a 45-degree angle fence where you want the character to be able to walk along either side of the fence. The character could be behind the fence but below the pivot point, or in front of the fence but above the pivot point, and in both cases the layering will be wrong. I've been trying to find an elegant solution to this but I just can't think of one other than adding trigger colliders to the objects that I use to manually layer the character when he is in certain areas around the object, but that's really cumbersome to set for every object in the world (and trigger colliders are buggy!!!). Any thoughts on a better solution here?
     
  36. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello,
    Thanka a lot. I am glad you like PolyNav :)

    Regarding your 1st question, it doesn't matter whether or not the polygon is a box of a polygon because in the end the thing that matters is the number of vertices it has for PolyNav. The colliders are just used for generating the nodes out of their vertices, so feel free to use PolygonColliders. As long as you dont dynamicaly change the navigation map, you can have a lot of them.
    Regarding your 2nd question, I havent give a thought about this. If I come up with any ideas I will let you know :)
    Cheers!
     
  37. Ravanok7

    Ravanok7

    Joined:
    Jul 7, 2013
    Posts:
    8
    I have a noob question! How can i avoid being sent for a ride? My agents are not avoiding each other. Even with the avoid radios set. They just shove each other into my player and well, Take me for a ride. Which is fun and all but i sort of don't want that :D
     
  38. iso250

    iso250

    Joined:
    Apr 19, 2015
    Posts:
    28
    Hello Nuverian.

    I received an email stating that PolyNav has been updated. Could you please advise which scripts have been updated? That way I can import only the scripts I need to update as I have made some changes for my project.

    Thank you for an awesome script. :)
     
  39. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    I would like to suggest a new feature / improvement of the asset.
    I use "agent.SetDestination" and it works ok but it doesnt go to the exact point that I want it to go.
    E.g: agent.SetDestination(new Vector(2.35f,1.326f)); The agent will one time end up at Vector(2.32f,1.31f) or Vector(2.36f,1.328f).
    Can you make another function maybe called agent.SetExactDestination to go to the exact point, this is very usefull in my adventure game that I make fixed animations that run after the agent (aka character) goes somewhere. Eg: The agent goes to the door and then an animation is run to open the door. I want the agent to go to the exact point so that his hand will match the door handle. Waiting your thought about this.
     
  40. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hey :)
    You can set the stopping distance of the red characters to be a bit bigger, so that they stop before they start pushing the blue one to avoid this situation.

    Let me know if this works for you.
    Thanks.

    Hey,
    The important change of the last version was made to the AStart.cs script where the performance was improved.
    Thanks.

    Hey George,
    If you set the stopping distance to an extremely low value like 0.001 the agent should stop at the location provided (+- 0.001). Can you please confirm. If this doesn't work for you, I will see to creating a more snappy version of SetDestination like you suggest :)
    Cheers!
     
  41. iso250

    iso250

    Joined:
    Apr 19, 2015
    Posts:
    28
    I use a stopping of 0.0005 and they stop right on the mark. I've found that when you use such a small number that you really need to pay attention to the slowing distance and deceleration to prevent them from coming to a very sudden stop when they reach their destination.
     
  42. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    I have set it at 0.0005 and I ask it to go to: Vector(-4.1f,-3.97f)) and it goes to Vector(-4.090754f,-3.970973f)) its close but not exact! A new function that also considers the stopping if its set to 0.01 would be perfect.
     
  43. iso250

    iso250

    Joined:
    Apr 19, 2015
    Posts:
    28
    Have you adjusted the slowing distance and deceleration? They can have an effect on the final stopping location.
     
  44. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    No, didnt have time to play with those.
     
  45. Fernandxor

    Fernandxor

    Joined:
    Oct 13, 2014
    Posts:
    23
    Hi nuverian, thanks for the code. But I think we are missing something here. When you set the agent's max speed, you are telling him to increase or decrease speed in both X and Y. It works fine, but only when you think of an ortographic camera. If you are faking a perspective (like in many graphic adventures) it does not work.

    Take this example: we have the game camera almost on the ground (zero height) so you can't notice too much Y axis movement. When the character (agent) walks right and left, it does pretty fast, which is ok, but as far as he goes to the background (faked by a tiny Y variation and very noticeable scale resize), the speed should be muuuuuuch slower in the Y axis. There is no visual distance in that axis because the camera is placed very close to the floor, while agent should keep almost the same horizontal speed when he goes left or right (X axis).

    I don't know if I explained well.

    I tried to find a way to move my character that way, but the agent won't perform that way, but instead it will move like a top-view game. May be internally, you could define a "Y axis perspective enforce" or something like that, that makes agent walk slower in that axis depending on the value you set, while keeping X speed independent. I know it may sound crazy xD

    Cheers!
     
    Last edited: Feb 16, 2016
  46. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    81
    @nuverian Is there a way to not only change the rotation speed, but also the needed turning space/area?
    So e.g. a ship can't change it's direction on the starting point, but is moving + turning at once to face the goal.

    Thanks in advance, John
     
    Last edited: Feb 14, 2016
  47. nuverian

    nuverian

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

    Hello,
    I understand what you mean, but right now, since the maxSpeed is a float parameter, this is not really possible without some hacks. One way I can think this happening, would be to take into account the current movingDirection of the agent and alter the moving speed based on that. I can't come up with a solution right now, but as soon as I do, I will come back and post it :)
    Another way, would be to change the source code to make the maxSpeed a Vector2 instead of a float and thus possible to be handled differently for each axis.

    Cheers!

    Hey,
    Do you mean a way for the agent to only turn when it's moving? I am not sure I understood what you mean exactly. Sorry. Can you please clarify a bit?

    By the way, you can turn off the "Turn Transform" option in the inspector, if you want to handle the rotation in any custom way through another script.

    Thanks.
     
  48. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    What about the feature I mentioned. It will be handy if it it also calculates the stopping distance and stop exactly at the spot you said.
     
  49. Ravanok7

    Ravanok7

    Joined:
    Jul 7, 2013
    Posts:
    8
    the ones pushing me are being pushed by the ones behind them to get to me, if i make the stopping distance large the enemy will stop too far away and will probably still be pushed towards me by all the other agents that have not reached the stopping distance, could this be an issue with rigidbodies?
     
  50. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    81
    @nuverian: Attached you a small picture to clarify what I mean.
    So normally the green path is how poly nav is currently working.
    The red path is what I want to achieve. So the agent should move and is only alowed to turn a specific radius at a time(or per frame).
    Is this something you could add and/or imagine some other people could use too?

    Thanks, John
     

    Attached Files: