Search Unity

SimplePath - Advanced Pathfinding for any Game Genre - RELEASED

Discussion in 'Assets and Asset Store' started by alexkring, May 18, 2011.

  1. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Thank you for your answer and continued support.. I will try your suggestions as well as IsBlocked that I've found couple of posts back. What I ment about 1) is:

    function CommandMove (pos:Vector3,look:Vector3){

    if (agent.MoveToPosition (pos,0.5)){
    animation.CrossFade("move",0.2);
    } else { Debug.Log("Can't Go"); }
    }

    I was suspecting that agent.MoveToPosition will return true and thus play the animation for the above example, only if the agent actually CAN go there, else will log "can't go".. I guess my assumption was then incorect? <edit: never mind the questionmark :)

    Will try your suggestions.
     
    Last edited: Jul 26, 2012
  2. otterbytes

    otterbytes

    Joined:
    Apr 11, 2012
    Posts:
    9
    Forgive me if this has already been asked (38 pages!), but is the source code in JS or C#?
     
  3. otterbytes

    otterbytes

    Joined:
    Apr 11, 2012
    Posts:
    9
    Nevermind I just found the answer, C# :(
     
  4. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    I strugle to find the distance to a succesfully requested path. I think this could be easier, but I though of doing this by the Count of nodes in the GetSolutionPath but I have an issue in this:

    var nodeCount:Vector3[] = pathRequest.GetSolutionPath(pathAgent.PathManager.PathTerrain);

    I get ""InvalidCastException: Cannot cast from source type to destination type.""

    Isn't the GetSolutionPath a Vector3[] ? Or if there is an easier method to do, please do tell.
    Thanks

    --Edit: Nevermind the error. It was irrelevant and saw that just now, alltough I still struggle to get this done :/
     
    Last edited: Jul 28, 2012
  5. yemo

    yemo

    Joined:
    Jul 18, 2012
    Posts:
    4
    Could you please help me with the actor_patrol moves on axis z or forward,,,

    thanks alex
     
  6. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    If someone here can help me out I appreciate. I just don't know what I am doing wrong here.
    This which is part of a function:
    Code (csharp):
    1.  
    2.     for (var slot:Transform in allSlots){
    3.  
    4.         if (pathGrid.PathGrid.IsBlocked(slot.position) == false) {
    5.  
    6.             var targetPos:NavTargetPos = new NavTargetPos(slot.position, pathAgent.PathManager.PathTerrain);
    7.             var pathParams:PathPlanParams = new PathPlanParams(transform.position, targetPos, 10);
    8.             pathAgent.RequestPath(pathParams);
    9.             yield; 
    10.             var pathRequest:PathRequest = new PathRequest();
    11.             if (pathRequest.HasSuccessfullyCompleted) {
    12.  
    13.                 var pointArray:Array = pathRequest.GetSolutionPath(pathAgent.PathManager.PathTerrain);
    14.  
    15.             }
    16.         }
    17.     }
    18.  
    Gives me this, where "UnitControl.js:101" is :
    "var pointArray:Array = pathRequest.GetSolutionPath(pathAgent.PathManager.PathTerrain);"


    NullReferenceException: Object reference not set to an instance of an object
    SimpleAI.Navigation.PathRequest.HasSuccessfullyCompleted () (at Assets/Plugins/SimplePath/Main/Code/AI/Navigation/Pathing/PathRequest.cs:232)
    SimpleAI.Navigation.PathRequest.GetSolutionPath (IPathTerrain terrain) (at Assets/Plugins/SimplePath/Main/Code/AI/Navigation/Pathing/PathRequest.cs:178)
    UnitControl+$CheckPath$25+$.MoveNext () (at Assets/Scripts/Various/UnitControl.js:101)

    I obviously do something wrong and am too blind to see.
    Thanks
     
  7. otterbytes

    otterbytes

    Joined:
    Apr 11, 2012
    Posts:
    9
    Alex,

    Just purchased this a few days ago, thanks for such a great product! So far we've been able to find most of the answers needed from this thread. But there's one thing I'm still stuck on.

    My Agent is using the Interaction Patrol script. What I want to do is have him walk at his normal speed until he reaches his first patrol point, then have him slow down to a "patrol speed". I was trying to use m_bNavRequestCompleted() to determine when he reached his first patrol point but this seems to be fired as soon as he starts to head towards his first point, and not once he reaches it.

    Can you tell me how I can achieve this? I would also need to know how to reset it because once I give him a new set of Patrol Nodes (for a new target) I will want to know when he reaches his first patrol node from the new assigned path.

    Does this make sense? Any help is appreciated. Thanks!
     
  8. GermyGames

    GermyGames

    Joined:
    May 20, 2012
    Posts:
    38
    I've got a few questions.

    1. Is there a way for agents to use gravity? I have a rigid body on my agents with use gravity checked, but they often glide through the air when going to a destination over uneven terrain.

    2. How do I make agents path around each other as if they have a footprint component?

    3. What's the proper way to completely stop an agent from pathing? (eg. An enemy is dead and no longer needs to move or solve a path to the player)
     
  9. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Look at m_path.totalPathLength in SteeringAgentComponent
     
  10. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    The OnNavigationRequestSucceeded message is sent to the agent gameobject when the agent reaches his destination, you could hook your code there.
     
  11. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    1. Look at the m_gravitationalAccelerationRate variable on the SteeringAgentComponent. This, along with the mass of the rigidbody, determine the total downward gravitational force.

    2. You'd have to experiment with this, theres not out of box solution, but id recommond good target selection, collisionse and/or improved steering code.

    3. Call CancelActiveRequest on the navigationagentcomponent.
     
  12. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Yes, I could/can use totalPathLength but we don't know if we keep the steering system yet (possibly we do if you make the update you talking about).
    In eithercase though, I don't understand why my above posted code doesn't work. Anyway.
     
  13. Chmyke

    Chmyke

    Joined:
    Aug 1, 2012
    Posts:
    34
    Hi Alex and thanks for this awesome pathfinder, it 's really simpler and quicker to use than A*pathfinding project!

    I think I want to do the same thing than ngaliod with his vertical scroller:
    So we have a camera who follow the player (top view).
    I have put the PathGridWithObstacles as child of the camera, so my grid follow the camera.
    I had problem with the detection of new obstacles find by the grid when it move, but I solved it by adding :
    Code (csharp):
    1. m_pathGrid = GetComponent<PathGridComponent>().PathGrid;
    on the Update of the script call "ObstacleGridComponent"
    (this is the only thing I changed of your code for the moment)

    But now I have another problem:
    When I move the grid I get an error :

    ComputePortal failed to find a neighbor

    UnityEngine.Debug:LogError(Object)
    SimpleAI.Navigation.GridPortalComputer:ComputePort al(Vector3, Vector3, PathGrid, Vector3, Vector3) (at Assets/SimplePath/Main/Code/AI/Navigation/Pathing/PathGrid.cs:280)
    SimpleAI.Navigation.GridPortalComputer:ComputePort als(Vector3[], PathGrid, Vector3[], Vector3[]) (at Assets/SimplePath/Main/Code/AI/Navigation/Pathing/PathGrid.cs:245)
    SimpleAI.Navigation.PathGrid:ComputePortalsForPath Smoothing(Vector3[], Vector3[], Vector3[]) (at Assets/SimplePath/Main/Code/AI/Navigation/Pathing/PathGrid.cs:116)



    and the generated path of my units is really strange...



    Have you tips to fix that?
     
    Last edited: Aug 2, 2012
  14. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    Hi Alex,

    Recently I have been testing changing the quality settings and noticed that the value of "VSync count" can have a really big effect on the speed of the units that simplepath is moving around in my game. Is there anyway to get the units to move around at a standard speed regardless of the framerate?
     
  15. huruena

    huruena

    Joined:
    Jul 31, 2012
    Posts:
    2
    Hola Alex,
    I'm trying to create prefabs associated with the path but always lost the connection between the new path and the existing prefab locree equally well from a prefab instantiated to the game starting. Has anyone had this problem? As we have managed to solve?

    Thks,

    Huruena
     
  16. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    invadererik: Take a look in SteeringAgentComponent.cs. You will notice there is only one location where the velocity of the agent gets set to anything other than 0. I'm not familiar with "vsync count", but you should be able to factor in any changes you want here. You can also see where the Time.deltaFrameTime gets factored into the speed of the agent in here.
     
  17. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    huruena: I'm sorry I don't think I understand the question.
     
  18. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    I'll take a look at SteeringAgentComponent.cs when I get home, but here is the setting in unity project prefs

    $vsync.jpg
     
  19. leonardoaraujo

    leonardoaraujo

    Joined:
    Jun 3, 2010
    Posts:
    87
    Hi Alex I've have a custom terrain mesh (Exported from Sketchup geo-location) and imported into Unity with the TM4 tool. I would like to use the PathGridWithObstaclesAndHeightmap, but as you already told I should pre-calculate the heightmap information on the IHeightmap.

    The question is do you have a sample or show us how I could extract this height information from the mesh (It's about scanning every point on my terrain and create a sort of array with it?) maybe if it's slow I can do it on the scene loading...
     
  20. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    I don't have any examples of making a custom heightmap. The only example I have in the package that uses the heightmap is the sceen that uses the Unity Terrain asset. There is some information in the docs about how to make a custom heightmap. Basicallt you need to inherit from the heightmap interfaces (I think they are IHeightmap and ITerrain). Take a look at the scene that uses the Unity Terrain asset, and hopefully that will be helpful.
     
  21. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    After careful examination, I think the problem is on my side, because I changed the SteeringAgentComponent and other parts of SimplePath code to use a character controller instead of a rigidbody. Sigh, I guess I should have left it as a rigid body. Sorry to waste your time Alex.
     
  22. tool55

    tool55

    Joined:
    Jul 10, 2009
    Posts:
    334
    With regard to question 2, is it ok to just add a footprint component to each agent so they path around each other? Or is this too expensive? Also, a second question with regard to the grid: Is there a way to reduce the footprint for objects that are angled from the grid or oddly shaped? I have boulders and structures in my scene and I notice that when the player gets into a red footprint zone (I'm using your follow script) the pathing stops and the agent freezes, presumably because the player becomes inaccessible. I suppose I could make the grid count much higher, but I would also imagine that there's a large performance hit for that.
     
  23. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    I'm using ToolKit2D and we have a BETA version of the tileset editor. This is quite stable at the moment and it allows me to draw tiles and use layers. Taking a look at my screenshot I have 2 layers (located inside the hierarchy) named Ground and Objects. Inside my Objects layer I have a box collider (highlighted inside the scene view).

    Would SimplePath work with this?

     
  24. malcroff

    malcroff

    Joined:
    Jul 3, 2012
    Posts:
    4
    Is there a possibility that SimplePath can find a path other than the shortest one? Sometimes in games we need the more obvious way like going trough walls, I don't want the player to be stuck on the left or the right wall, but on the middle. So is it possible to find a more optimal path?
     
  25. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Hey @alexkring, is there an existing way to simply make the object face the way they are moving via the steering agent?

    Thanks!
     
  26. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Adding footprint components to the agents wont work because they will try to avoid themselves, unfortunately.

    If you want more sophisticated footprint calculations, you'll have to modify the code in ObstacleGridComponent.cs (also take a look at FootprintComponent.cs). There is also a variable on the footprint component that determines how far the footprint extends from the extents of the object with the footprint component.
     
  27. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Yes
     
  28. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    You can modify the heuristic to change the search (look at GetHCost and GetGCost). Another option is to change your destination selection to be more intelligent (writing some code to be more intelligent about the search's destination).
     
  29. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    A few posts back I posted a link to a new SteeringAgentComponent.cs file that handles this for you. If you look through the forums you should be able to find this, and just replace this with your existing SteeringAgentComponent.cs
     
  30. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Hey Alex, thanks for the prompt reply (page 34 if anyone else was looking for this). Works a treat! Many thanks
     
  31. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Hey Alex anther simpler question - the footprint, when I place one in the editor and then run my game, it appears to scale and align to the cell in the pathgrid. I'm not sure how to place a footprint down, so its scale and position in the editor are exactly the same as when I run the game - I assume it's to do with the Scale varaible in the script? Also - should I be using the scale in the transform, or this scale variable in the FootPrint Component?

    Thanks!
     
  32. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    Out of the box, or would it need some tinkering to get it working?
     
  33. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    It should work out of the box, but any game will likely require some coding for special cases. I think you could quickly get the agents moving around without any coding though.
     
  34. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    You can use both scale values. The scale in the footprint component determines the amount of footprint padding around the obstacle.
     
  35. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    And how do I ensure the footprint in the editor is aligned with the footprint when I run the game?
    Thanks
     
  36. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    The footprint calculation is axis-aligned. If you don't want this to be the case, you will have to write maybe a dozen or so lines of code to compute the non-axis aligned projection of the collider onto the terrain. In other words, given the collider's boundaries, what are the cells that are blocked. You can start by taking a look at the Rasterize() function, where this is computed. There should only be one function that you need to change.
     
  37. jonboris

    jonboris

    Joined:
    Jan 8, 2009
    Posts:
    78

    Hi, I was wondering if you ever got this working?

    I tried doing this but got the same problem as Ngaliod (grid moves but agents don't recognize the new grid pos)

    I'm creating an infinitely generating maze so it would be great if the grid can move as the player moves

    Thanks!
     
  38. Korolev

    Korolev

    Joined:
    Sep 20, 2012
    Posts:
    22
    Tell me how to get an agent to turn on the way.
    And if he stands with his back to goal, turn around first, and only then begin to move?
    Thanks in advance!
     
  39. ibrahimarslan

    ibrahimarslan

    Joined:
    Aug 25, 2010
    Posts:
    24
    Hi alex making a tower defance game , my question is how finding mouse position and find grid number or positon ?

     
  40. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
  41. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
  42. awejk

    awejk

    Joined:
    Oct 13, 2012
    Posts:
    32
    Hello,

    I'd like to use your pathfinder in 2d iso game. I have the following axis .
    But I can not rotate the PathGridWithObstacles for no axis.
    how to do it?
     
  43. Boji

    Boji

    Joined:
    Jul 10, 2012
    Posts:
    44
    Hi, how can I make a footprint that rotates when an object is rotated? Right now all footprints are rectangular and perpendicular to the grid and only change size when a object is rotated.

     
  44. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    You will need to add that code yourself. You can start by looking at the Rasterize() function to see how the colliders are projected onto the grid to form the footprints. You shouldn't have to write too much code. Someone posted code for this before, but you'll have to search through the thread to find it.
     
  45. Boji

    Boji

    Joined:
    Jul 10, 2012
    Posts:
    44
    Yeah, the code is in the Footprint component but I'm stuck with getting it to work and I can't find any code in this thread to help me...
     
  46. bardic

    bardic

    Joined:
    Feb 8, 2012
    Posts:
    10
    Hey Alex,
    Just picked up simplepath as it looks pretty cool, but when I import, all the objects in the tests scenes are broken. Any ideas on now to fix this?

    Thanks
     
  47. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Are all the files being imported? What platform do you have set in your build settings? (ex: ios, pc, android). Can you try importing into a brand new project, so that SimplePath is the only thing in your project, to ensure there is not some conflict with your existing code and assets? I haven't seen this problem with before, so it is likely a problem with your local setup, but I could be wrong. Let me know what you find out after trying these suggestions.
     
  48. bardic

    bardic

    Joined:
    Feb 8, 2012
    Posts:
    10
    Sorry for the delayed reply. Importing into a new projects worked ^^
     
  49. yemo

    yemo

    Joined:
    Jul 18, 2012
    Posts:
    4
    Hey Alex.

    I am really new in this thing and i would like you help me.... where do i have to change a code line to Actor patrol o actor wander all-ways go in the z axis,,, you know a object 3d always walk in z axis

    Thanks
     
  50. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    Hey again simple path forum thread! I had a question about how one would go about doing steering "forecasting". I was thinking about just attaching trigger colliders to all my actors and then coding in the OnCollisionEnter/OnCollisionStay events that are generated from that. I was wondering if there was maybe an easier/more generally accepted way to make the various actors aware of each others positions, destinations, and possibly movement states or if I was indeed barking up the correct (and rather tall) tree.