Search Unity

SimplePath - Advanced Pathfinding for any Game Genre - RELEASED

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

  1. machy

    machy

    Joined:
    Apr 27, 2012
    Posts:
    2
    Searching in this forum, now I understand SimplePath license is valid for commercial use. But I have some additional questions. Is SimplePath license per-person or per-studio? If we purchased a license, do we use it for multiple projects?

    Also, we are developing a game for another company who will take possession of all the game's source code. In this case, does our client also need a SimplePath license?
     
  2. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    You only need one license for your entire studio, and you can use it for as many projects as you like. The company that owns the source code will not need a license. So basically, you just need to buy one license.
     
  3. machy

    machy

    Joined:
    Apr 27, 2012
    Posts:
    2
    Thank you alexkring! We'll buy one!
     
  4. Lord-Simpson

    Lord-Simpson

    Joined:
    Mar 24, 2011
    Posts:
    10
    Just wondering can simple path use unity terrain as an obstacle "out of the box"?

    I'm making a water based game and want pathfinding around land (say any terrain above -10 ingame units to prevent bottoming out). Looked through the thread and the documentation but can’t quite make out if the pathfinding works in such a way that this would be possible / easy to implement.
     
  5. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    This video shows the agent pathfinding using unity terrain. This demo scene comes with SimplePath, to show you how to hook Unity Terrain into SimplePath, and it is "out of the box." However, getting units to avoid certain parts of the terrain, based on height, is not out of the box, but it would not be difficult to implement. The code you would need to write, would look something like this:

    Code (csharp):
    1.  
    2.                 private void RasterizeTerrainHeight()
    3.         {
    4.             for (int colIndex = 0; colIndex < numCols; colIndex++)
    5.             {
    6.                 for (int rowIndex = 0; rowIndex < numRows; rowIndex++)
    7.                 {
    8.                     Vector3 cellPosition = GetCellPosition(rowIndex, colIndex);
    9.                     float height = GetTerrainHeight( cellPosition );
    10.                     const float kMinHeight = -10.0f;
    11.                     if ( height < kMinHeight )
    12.                     {
    13.                         SetSolidity( cellPosition, true );
    14.                     }
    15.                 }
    16.             }  
    17.         }
    18.  
    And then at the end of the Rasterize() function in ObstacleGridComponent.cs, you call RasterizeTerrainHeight().

    I'll try to make sense of this in plain english. The ObstacleGridComponent is the component attached to the grid, that determines which parts of the terrain are walkable, and which parts are unwalkable. Currently it just looks at all of the obstacles in the world, and rasterizes them into the grid to determine tell the grid that locations with obstacles are not walkable. This function is additionally informing the grid that locations underwater are also unwalkable.
     
    Last edited: May 2, 2012
  6. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    I am trying to build to Android and it just terminates the process and I get this warning:

    Script attached to 'PathGridWithObstaclesAndHeightmap' in scene '' is missing or no valid script is attached.
    UnityEditor.HostView:OnGUI()

    I have no idea what this is referring to. I've searched for said object, and cannot find anything. Any idea about what on earth this is? Thanks.

    EDIT: Ok, turns out there was a corrupted object on a rogue scene which wasn't even being added to the build. Deleted the scene and now everything is ok.
     
    Last edited: May 8, 2012
  7. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    Hi Alex,

    Please can you have a look at this simple scene I made,.

    I have no idea what I'm doing wrong I've tried everything I can think of.
    SimplePath seems to have lots of issues with spawned prefabs. Either that or I'm totally missing something.

    The simple project has two actors. One that gets instantiated, and one that does not.
    The one that is not instantiated, is an exact replica of the other, and calling MoveToPosition() on it works fine.

    The one that is instantiated however, no matter what I do I cannot get it to move to the same point using MoveToPosition().

    I have checked all values/settings at runtime, and there is no difference between the two. Please can you tell me what I'm doing wrong in this simple scene, as this makes absolutely no sense.

    Thanks

    This person seems to have the same issues...
    http://answers.unity3d.com/questions/151860/simplepath-instantiated-ai.html
     
    Last edited: May 10, 2012
  8. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    I'll take a look at it over lunch today.
     
  9. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Can you upload it as a zip? I have a mac.
     
  10. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
  11. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    Hello simply path thread people! Based on the frequent support on this thread I decided to buy and integrate simple path as the pathing component in the game I am currently working on. First off I just wanted to say that I qualify myself as an extremely junior developer and have only the most basic passable knowledge of unity and her API's. My day job has me programming fairly extensively in perl and various shell languages and I have a passable knowledge of the basics of C# and general OOP. Having said that a lot of the questions and issues I might be bringing up from here forward may honestly pertain more to the general unity environment and not even simple path. So there's a big paragraph vaguely apologizing about my lack of experience. Now that I have that out of the way...

    In order to get a better working knowledge of simple path I setup a very simple scene. A 25x25x10 resolution terrain, a cylinder object as the playerObject and a cube as the enemyObject. I then added the requisite environmental simple path objects (the pathManager and pathGridWithObsticles), as well as the nav, steering, and path, components to the two game objects. My only goal here is to have the player cylinder travel to the worldspace location under where the players mouse is hovering (the general control mechanism for any RTS really) and then have various enemy actors path to the player when a trigger attached to the enemy is breached. I did some research and came up with this to move the character.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class moveIt : MonoBehaviour {
    5.     public float repan = 0.5f;
    6.     private Ray camRay;
    7.     private RaycastHit hit;
    8.     private NavigationAgentComponent navAgent;
    9.     private Vector3 moveLocation;
    10.    
    11.     void Awake () {
    12.         navAgent = gameObject.GetComponent<NavigationAgentComponent>();
    13.     }
    14.    
    15.     void Update () {
    16.         if (Input.GetButtonUp("Fire1")) {
    17.             camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    18.             if (Physics.Raycast(camRay, out hit)) {
    19.                 moveLocation = hit.point;
    20.                 navAgent.MoveToPosition(moveLocation, repan);
    21.             }
    22.         }
    23.     }
    24. }
    This actually worked a lot better then I thought it would. However I have noticed some wonky behavior if I have other enemyActor gameObjects trying to follow the cylinder. I will click in a location and the cylinder will take what appears to be a VERY erratic path to get there. I don't have any footprint components on my enemies. Should I?

    Next I made a simple script to have the cubes follow the player cylinder when they get inside a trigger sphere I have setup on them.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ai : MonoBehaviour {
    5.     public GameObject target;
    6.     public float replan = 0.5f;
    7.     private NavigationAgentComponent navAgent;
    8.    
    9.     void Awake () {
    10.         navAgent = gameObject.GetComponent<NavigationAgentComponent>();
    11.     }
    12.    
    13.     void Update () {   
    14.         if (target) {
    15.             navAgent.MoveToGameObject(target, replan);
    16.         }
    17.     }
    18.    
    19.     void OnTriggerEnter (Collider actor) {
    20.         if (actor.gameObject.tag == "Player") {
    21.             target = actor.gameObject;
    22.         }
    23.     }
    24. }
    Which seems to work pretty well too. The cube will successfully path to the players object without any issue. However when the cube touches the cylinder they disturb one anthers colliers and often tumble out of control. I'm sort of at a loss on how to deal with that particular issue. I have tried adjusting the Arrival Distance variable to prevent the two objects from actually colliding, but that didn't work (nor do I think in a real game I would be able to just unconditionally stop objects from hitting one another). Is there some way to get my "actor" game objects to simply slide off of one another rather then what appears to be the default behavior when 2 rigidbodies hit one another? Really any advice, general or extremely specific, would be greatly appreciated.

    Finally I had one other question about integrating use of the CharacterController component with SimplePath. Earlier in this thread I saw that you offered a rewritten version of the steeringpathagent that was wired to use the character controller component rather then a rigidbody component. My initial idea was to give my character the chracterController component and assign enemies the rigidbody component. Is it possible to have 2 versions of the steeringagent, one for the charactercontroller based objects and one for rigidbodies? I tried wiring this together but ran into all kinds of issues (likely cause I had to use a new name for the steeringagentcomponentCC for the character controller and the other components in simplepath are not instructed to expect or require a component of that type/name, correct?). This seemed to basically break everything. Really this sort of a minor thing but I figured I would put it up here anyways.

    I really appreciate the documentation provided with the software, and just reading through this thread and looking through the example scenes and objects in the package have been a huge help, but I feel like my general inexperience is causing me to make what are likely pretty boneheaded errors. Thanks a lot in advance for any help.
     
  12. pplthot

    pplthot

    Joined:
    May 15, 2012
    Posts:
    1
    I can't get more then 9 agents to use the Path Manager. I've set the max number of planners to 100 and nothing changes. Only 8 or 9 at a time will move around.

    EDIT: I didn't have the replan interval set right. Don't understand what it does, but I got it working.
     
    Last edited: May 15, 2012
  13. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
  14. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    The replan interval determines how frequently each agent replans his path. For example, the default value is 0.5. This means that for any given agent, he will plan his path, and then every 0.5 seconds, he will replan his path. The purpose of path replanning is to account for the dynamic nature of most game environments. Another common approach is to detect when a path is invalidated because of a dynamic change to the environment, and then plan a new path. In practice, I think it's better to accept the fact that the environment is going to invariably change, the game will constantly change, physics forces are unpredictable, and its's very time consuming and difficult to try to detect all possible cases where a path can be invalidated.
     
  15. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Regarding your physics issues: depending on your game, there are several options. You could lock the rotation on some of the axies. Most likely you only need yaw, and you probably don't need pitch or roll, so you would end up locking to of the rotation axies.

    Also note that there is a downward acceleration force applied to the agent every frame, to simulate gravity. You can control this in the SteeringAgentComponent.

    "collision response" is often part of some steering systems in games, and is one way of dealing with the dynamic nature of games. This mean that when an agent collides with an object, you would determine how this affects the agent receiving the collision. Unity has a collision callback where you can detect these events (The OnCollisionEnter message, or OnTriggerEnter). I'd recommend placing this callback in the SteeringAgentComponent, since structurally, the SteeringAgentComponent is the only code file that deals with forces, velocity, and the actual translation of the agent. A simple and common way to handle collision response, is to have the agent slide off of the object he is colliding with, as if the object were covered in slippery butter. To do this, you want to calculate the projection of the agent's velocity onto the normal of the object he is colliding with. Here's some reference I quickly looked up (http://stackoverflow.com/questions/...h-obstacle-avoidance-in-a-continuous-2d-space)

    You could also have the agent apply a force to the object he is colliding with.

    Or if two agents collide, you can make one stop moving for a short period of time (disable his navigation for maybe a second), and allow the other agent to keep moving. This is a pretty dumb algorithm, but it actually isn't that bad in practice. This helps to solve the problem of agents looking dumb when they continually ram into one another.

    Finally, I think it's important to understand the big picture about navigation. Navigation is 3 things: planning, steering, and collision response. There are a ton of ways to solve any given navigation problem. Some solutions rely more on planning, some more on steering, some more on collision response. Whenever you run into a problem or bug, think about these three categories as the tools you have to create a solution.
     
  16. bandingyue

    bandingyue

    Joined:
    Nov 25, 2011
    Posts:
    131
    Hello Alex Kring.

    I used your SimplePath.

    It is very good.

    But if a Rectangle Obstacle placed obliquely.

    will it be inaccurate?
     
  17. bandingyue

    bandingyue

    Joined:
    Nov 25, 2011
    Posts:
    131
    And I notice that

    for example in http://tieba.baidu.com/p/1602347772

    the agent can go straightly to the target.

    but it make a little offset then turn to the target again.

    why does not the agent go straightly to target?
     
  18. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    There are a few artifact cases where that happens, as you see in your image. In practice these happen infrequently, but it happens sometimes because of floating point errors in the path smoothing (I use the funnel algorithm for path smoothing). One fix to this is to do a straight line check to each path first, and if the agent can directly see his goal, then he just travels there. I didn't want to add this check, because I though the gains in performance here outweighed the gains in path quality. So, it's a balance between performance and quality. If your game needs the improvement to path quality, you should look at the following function.

    Code (csharp):
    1.  
    2. public void Raycast2D(Ray ray, out Vector3 isectPt)
    3.  
    Call this function at the beginning of the StartANewPlan function in AStarPlanner.cs. If the agent can see the path, then you should call ConstructSolution(), and set the plan status to ePlanStatus.kPlanSucceeded.
     
  19. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Yes, you will need to modify the RasterizeI() function in ObstacleGridComponent.cs to handle oblique objects.
     
  20. bandingyue

    bandingyue

    Joined:
    Nov 25, 2011
    Posts:
    131
    thank you for your respond . i am satisfied.

    perfermance or quality? sometimes it is hard to accept or reject.
     
  21. Astero

    Astero

    Joined:
    Mar 17, 2011
    Posts:
    115
    Hello, I have a question :
    I try to make an ennemy facing at his direction when he chase the player, (actually, he doesn't rotate at all in his walk direction) is it possible ? how ?
    Any reply would be great ! :)
     
  22. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Add this function to SteeringAgentComponent.cs.

    Code (csharp):
    1.  
    2. private void UpdateTurning()
    3.     {
    4.         Vector3 desiredLookPos = m_seekPos;
    5.         desiredLookPos.y = transform.position.y;
    6.         Vector3 desiredLookDir = desiredLookPos - transform.position;
    7.         desiredLookDir.Normalize();
    8.        
    9.         Vector3 angularAccelerationDir = Vector3.zero;
    10.         float cwSeekAngle = SimpleAI.PathUtils.CalcClockwiseAngle(transform.forward, desiredLookDir);
    11.         if ( cwSeekAngle < Mathf.PI )
    12.         {
    13.             angularAccelerationDir = Vector3.Cross(Vector3.up, transform.forward);
    14.         }
    15.         else
    16.         {
    17.             angularAccelerationDir = Vector3.Cross(transform.forward, Vector3.up);
    18.         }
    19.         angularAccelerationDir.Normalize();
    20.        
    21.         //Vector3 angularAccelerationDir = (desiredLookDir - transform.forward).normalized;
    22.         Vector3 angularAcceleration = m_angularAccelerationRate * angularAccelerationDir;
    23.         Vector3 targetAngularVelocity = m_currentAngularVelocity + angularAcceleration * Time.deltaTime;
    24.         float dotDiff = Vector3.Dot(desiredLookDir, transform.forward);
    25.         float diffInRadians = Mathf.Acos(dotDiff);
    26.         float clippedRotationSpeed = ComputeClippedRotationSpeed(diffInRadians, m_rotationSpeed, m_slowingAngleForAngularVelocity);  
    27.         m_currentAngularVelocity = PolylinePathway.TruncateLength(targetAngularVelocity, clippedRotationSpeed);
    28.         Vector3 newForwardDirection = transform.forward + m_currentAngularVelocity * Time.deltaTime;
    29.        
    30.         transform.forward = newForwardDirection;
    31.     }
    32.  
    Call it right after this line of code:

    Code (csharp):
    1.  
    2. // Set the new velocity
    3.             rigidbody.velocity = newVelocity;
    4.  
     
  23. Astero

    Astero

    Joined:
    Mar 17, 2011
    Posts:
    115
    Last edited: May 25, 2012
  24. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Here is a simpler, more straight forward answer. In the SteeringAgentComponent.cs file, Right after the line of code "rigidbody.velocity = newVelocity;", add the following code:

    // Turn
    Vector3 desiredLookPos = seekPos;
    desiredLookPos.y = transform.position.y;
    Vector3 desiredLookDir = desiredLookPos - transform.position;
    desiredLookDir.Normalize();
    float rotationDeltaInRadians = m_rotationSpeed * Time.deltaTime;
    Vector3 newForwardDirection = Vector3.RotateTowards(
    transform.forward,
    desiredLookDir,
    rotationDeltaInRadians,
    0.0f);
    transform.forward = newForwardDirection;

    And you should add a public variable called m_rotationSpeed, to this component. This value will control how fast your agent rotates. If you want more control over this (ex: angular acceleration and deceleration), I can give you code for that too. Also, delete the old code I sent to you.
     
  25. Astero

    Astero

    Joined:
    Mar 17, 2011
    Posts:
    115
    Thanks, it worked great I can now continue my personal work. And thanks again for that fast and efficient answer ! :)
     
    Last edited: May 25, 2012
  26. IMTRIGGERHAPPY9

    IMTRIGGERHAPPY9

    Joined:
    Jul 27, 2011
    Posts:
    35
    Hey i have a problem with an armature i put in unity from blender, its somehow offsetting my pivot point( or the center of my character by a ton, i have been messing around with it for about 2 hours now and i can't for the life of me figure it out, i tried putting it in an empty and editing it in blender. but it still seems to bounce when ever i push play. its following my path the way i want it to, but its floating like an airplane. and i am pretty sure its because of my pivot point. any idea how i would fix it?
     
  27. Astero

    Astero

    Joined:
    Mar 17, 2011
    Posts:
    115
    Have you ever tried to put your model in the center of the XYZ coordinates in the editor (inside Blender) before export it to Unity ?
    Or maybe add a rigidbody with gravity ON ?
     
  28. IMTRIGGERHAPPY9

    IMTRIGGERHAPPY9

    Joined:
    Jul 27, 2011
    Posts:
    35
    ha ha yup! both of them, the center of blender is right at the feet of my character, and the gravity checkmark is off. its very odd, i can't tell why its doing it, because i have another character that doesn't have an armature and it goes along my path perfectly while this one floats.
     
  29. Astero

    Astero

    Joined:
    Mar 17, 2011
    Posts:
    115
    Ah ok, sorry I have no idea then :( maybe the armature colliders conflict with an other one ?
     
  30. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    I had a quick question on how it would be best to turn a character to have them face "forward" along their path. I basically just want to get my actor gameObject to face the next point in their destination. When a path is plotted where would I be able to poll data about individual "nodes" or waypoints the character will be moving to? Structural I am assuming it would be wisest to put something like that in the steeringAgent code?
     
  31. Astero

    Astero

    Joined:
    Mar 17, 2011
    Posts:
    115
    He answered to that problem, just look a little up on page 34.
     
    Last edited: May 27, 2012
  32. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    What ist the mass of the object on the rigidbody component? Try increasing this.
     
  33. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    You can look at the steering code I posted for Astero. Here is another thing to note. The SeekPos, stored in the SteeringAgentComponent, always represents the position the agent is moving toward, at any given point in time. The turning code just makes the agent face toward this position.
     
  34. IMTRIGGERHAPPY9

    IMTRIGGERHAPPY9

    Joined:
    Jul 27, 2011
    Posts:
    35
    so how would i find the tag of the gameobject i found? cause currently i have this:


    FootprintComponent[] footprintArray = GameObject.FindGameObjectsWithTag("ObstacleGhost");

    and its throwing a gameObject[] to footprintcomponent[] error so how would i fix this?

    p.s. i figured out the other thing about the floating character. it works now thank you.
     
    Last edited: Jun 4, 2012
  35. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Code (csharp):
    1.  
    2. GameObject footprintObjectArray = GameObject.FindGameObjectsWithTag("ObstacleGhost");
    3.         FootprintComponent[] footprintArray = new FootprintComponent[ footprintObjectArray.Length ];
    4.         int i = 0;
    5.         foreach ( GameObject footprintObject in footprintObjectArray )
    6.         {
    7.             footprintArray[ i ] = footprintObject.GetComponent<FootprintComponent>();
    8.             i++;
    9.         }
    10.  
     
  36. seedoubleyou

    seedoubleyou

    Joined:
    Jul 24, 2011
    Posts:
    2
    I'm looking for a simple way to know when the character/agent has reached the end of a path. There must be a place in the code where this is declared or a message that's sent out, but I can't seem to find it.


    (NEVERMIND: I used the rigidbody.velocity in the SteeringAgentComponent script. When the rigidbody.velocity.x value fell to zero, I knew I could tell my model to stop the motion animations. )
     
    Last edited: Jun 5, 2012
  37. IMTRIGGERHAPPY9

    IMTRIGGERHAPPY9

    Joined:
    Jul 27, 2011
    Posts:
    35
    that threw a bunch of errors: Cannot implicitly convert type GameObject[] to GameObject so i changed that to this

    GameObject[] footprintObjectArray = GameObject.FindGameObjectsWithTag("GhostObstacle");
    print(footprintObjectArray.Length);
    FootprintComponent[] footprintArray = new FootprintComponent[ footprintObjectArray.Length ];

    int j = 0;

    foreach ( GameObject footprintObject in footprintObjectArray )

    {

    footprintArray[ j ] = footprintObject.GetComponent<FootprintComponent>();

    j++;

    }

    but its not working, it can't tell the difference between them the two tags.

    sorry, i dont get why.

    i put the code above right before the foreach( footprintComponent footprint in footprintArray) so right before it finds where its blocking?

    if it helps any i have the Obstacle_Box as a child of another parent gameobject
     
    Last edited: Jun 5, 2012
  38. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Sorry that was a typo.

    Code (csharp):
    1.  
    2. GameObject[] footprintObjectArray = GameObject.FindGameObjectsWithTag("ObstacleGhost");
    3.  
    4.         FootprintComponent[] footprintArray = new FootprintComponent[ footprintObjectArray.Length ];
    5.  
    6.         int i = 0;
    7.  
    8.         foreach ( GameObject footprintObject in footprintObjectArray )
    9.  
    10.         {
    11.  
    12.             footprintArray[ i ] = footprintObject.GetComponent<FootprintComponent>();
    13.  
    14.             i++;
    15.  
    16.         }
    17.  
     
  39. IMTRIGGERHAPPY9

    IMTRIGGERHAPPY9

    Joined:
    Jul 27, 2011
    Posts:
    35
    I fixed the typo last time but it wasn't caring what tag my obstacle box's had it would use all of them as blocks
     
    Last edited: Jun 6, 2012
  40. ninjamint

    ninjamint

    Joined:
    Nov 26, 2009
    Posts:
    9


    How do I fix this? I have increased the "Max Number Of Nodes", and nothing. Any ideas?
     
  41. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    Turn on all the debugging information in all of the SimplePath components. Is the path being drawn? Are there any lines being drawn by the steering component? What are the values for everything on the PathManagerComponent?
     
  42. rroxxy

    rroxxy

    Joined:
    Jun 11, 2012
    Posts:
    2
    Hi!
    Is there a way to make the agents pause between requests?
    I tried to add waitforseconds but it returns errors... :(


    Code (csharp):
    1. private void OnNavigationRequestSucceeded()
    2. {
    3. m_bNavRequestCompleted = true;
    4. yield return new WaitForSeconds (Random.Range(2,7));
    5. }
     
  43. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    You are attempting to start a coroutine (the WaitForSeconds call) within a function that does not have a return type of IEnumerator. Here is an example of how to make use of coroutines with SimplePath.

    Code (csharp):
    1.  
    2. // Usage: yield return StartCoroutine( MoveToPositionBlocking( targetPosition ) );
    3.     //
    4.     // Ex:    yield return StartCoroutine( MoveToPositionBlocking( targetPositionOne ) );
    5.     //        yield return new WaitForSeconds( 2.0f );
    6.     //        yield return StartCoroutine( MoveToPositionBlocking( targetPositionTwo ) );
    7.     //
    8.     private IEnumerator MoveToPositionBlocking(Vector3 targetPosition)
    9.     {
    10.         if ( m_navAgent.MoveToPosition( targetPosition, m_replanInterval ) )
    11.         {
    12.             while ( !m_bNavRequestCompleted )
    13.             {
    14.                 yield return false;
    15.             }
    16.         }
    17.     }
    18.  
     
  44. rroxxy

    rroxxy

    Joined:
    Jun 11, 2012
    Posts:
    2
    Thanks a lot for this, thats exactly what I needed!

    I have to say SimplePath is a fantastic pathfinding solution!

    Can I ask you one more thing please,

    Is there a way to implement "Running away" behavior?

    In "Interaction_Chase" example the agent runs towards the target, is there a way to make it run away from the target?

    One agent is running away, the other one is chasing it, it could be very useful
     
  45. 3dever

    3dever

    Joined:
    Mar 2, 2009
    Posts:
    71
    Finally, what about Flash export support? A* doesn't support it. What about SimplePath?
     
  46. 3dever

    3dever

    Joined:
    Mar 2, 2009
    Posts:
    71
    Can i hope for the answer? :( someone with license, please test Flash export
     
  47. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    I just tried building it in flash. It looks like there are still some bugs with Unity building to flash. The builder is unable to build a class that uses generics.

    http://forum.unity3d.com/threads/116549-Cannot-build-Flash
     
  48. pated

    pated

    Joined:
    Jun 27, 2012
    Posts:
    31
    Hi Alex,
    First of all, thank you for your excellent plug-in! I bought it several months ago and it helped a lot.
    I need a piece of help if you don't mind.

    I'm working on some kind of vertical scroller (to be simple). Each level is a bit huge so instead of creating a very long simplepath pathgridwithobstacles I wanted to have a small grid that I move every ~30 seconds a few hundred units forward as the player is advancing.

    Naively I first tried to simply move the pathgrid gameobject every 30 seconds by code. The grid GUI display moves, however the agents remain at the original position of the grid.
    So I suppose I have to redraw the grid every time I want to move it... am I right? Could you please tell me where to look at? My first guess would be to add a new function that I call in PathGridComponent that I call to redraw m_pathTerrain.

    Big thanks for your help.
     
  49. alexkring

    alexkring

    Joined:
    May 5, 2011
    Posts:
    368
    So it sounds like you want your characters to move relative to the grid origin, rather than relative to the world origin, is this correct? In other words, it sounds like you want to parent the characters to the grid.

    Do the characters still need to be pathfinding when you are moving the grid? Or can they stop while the grid is being moved, and wait until it comes to a rest?

    Also, I'm not familiar with the "vertical scroller" game genre. Did you mean vertical shooter? If you could post screenshots or a demo, I will have a better chance at fixing your problem. Thanks :]
     
  50. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hi,
    Doesn't simplepath allow for not horizontal and vertical obstacles? Does it only allow boxed obstacles?
    Thanks.