Search Unity

UnitySteer - steering library for Unity

Discussion in 'Scripting' started by Arges, Jul 9, 2009.

  1. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Hello everyone,

    It's a pleasure to finally release UnitySteer, a library of steering components for Unity, covering anything from path following to obstacle avoidance to following neighboring vehicles. You can find more details, as well as the source code and a few examples, here.

    The library is under the MIT license and hosted on Github, so contributions are welcome.

    Cheers!
     
    Last edited: Jan 17, 2014
  2. Ramen Sama

    Ramen Sama

    Joined:
    Mar 28, 2009
    Posts:
    561
    wow, i think i could really use something like this!
     
  3. Martin-Schultz

    Martin-Schultz

    Joined:
    Jan 10, 2006
    Posts:
    1,377
    Just brilliant!
     
  4. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Ricardo, very interesting. Thank you for sharing this with the community. One question: What do you mean by "Vehicle tethering" in your features description?

    EDIT: Never mind. I took a look at your project and that answered my question. Nice! :)
     
  5. magwo

    magwo

    Joined:
    May 20, 2009
    Posts:
    402
    Wow, not bad.

    Does it handle bunching/congestion/queueing gracefully in some way?

    As in.. does it attempt to go another route if another entity is blocking a path, but is moving?
     
  6. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    magwo:
    UnitySteer implements pathfollowing - currently directly linking up to Path (I'm gonna do some work on this part when my vacation starts next week), so in terms of getting a path recalculated based on congestion, this is something you'd have to set up in a parallel system - tracking clumps of characters and adjusting Path connection/node weights based on that.
     
  7. Joe-Robins

    Joe-Robins

    Unity Technologies

    Joined:
    Apr 21, 2008
    Posts:
    430
    Great work! :D
     
  8. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    It can help handle them gracefully, in the sense that it'll do its best to ease the vehicle among the currently known neighbors, plus they can all avoid colliding with each other, but repathing is beyond the scope of the library since it doesn't handle pathing by itself.

    Like Emil points out, repathing would require your pathfinder to know that a node is more expensive because it has more objects on it, which not only depends on your pathfinder but on your specific game constraints.

    Of course it can be built upon to accommodate it - you'd start on the PathFollower vehicle and the Pathway classes.

    (Edited for extra details)
     
  9. psychicparrot

    psychicparrot

    Joined:
    Dec 10, 2007
    Posts:
    884
    WOW. This is an awesome library!

    Thanks for sharing :)
     
  10. HJP

    HJP

    Joined:
    Jul 8, 2009
    Posts:
    152
    Awesome .... Thanks for sharing!
     
  11. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Glad you guys like it, do let me know if you build anything with it. :)

    Cheers,
     
  12. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Awesome, thanks for sharing it! :D
     
  13. MitchStan

    MitchStan

    Joined:
    Feb 26, 2007
    Posts:
    568
    Thanks for porting the steering library. When I download the project and open it, I receive several warnings:

    "Couldn't load the script xxxxxxx becasuse it's file name doesn't match the class name. Please make sure the file name of the script is the same as the class defined inside it."

    Is this normal? Any thoughts how to remedy these errors and get the project working. Thanks for any help with this.

    Mitch
     
  14. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Hello Mitch,

    These are actually warnings, not errors. It's normal, and shouldn't stop your project from running.

    I've seen this with standalone class files - my guess is that Unity is attempting to treat the class script the same way it treats MonoBehaviours, and when it can't it raises the warning.

    If there's anyone from Unity reading this, can you guys elaborate?
     
  15. MitchStan

    MitchStan

    Joined:
    Feb 26, 2007
    Posts:
    568
    I see - thanks for the info.
     
  16. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    This library is awesome thank you for sharing, Any way of suppressing the warnings? Those are pretty annoying.
     
  17. Hans

    Hans

    Joined:
    Feb 20, 2007
    Posts:
    422
    thank you very much on the info and files, very very useful
     
  18. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Not right now. They'll go away in a future release of Unity.
     
  19. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I'm trying to create a pursue behavior that avoids obstacles, I'm using the WanderRadarBehavior from the obstacle avoidance example as reference, just replacing the wander part of it with a pursueBehavior.

    For some reason this doesn't work, my object pursues its target but goes over all the obstacles, I also don't see any of the red debug lines so I can only assume I did something wrong.

    Any pointers?

    here's how my class looks like
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using UnitySteer;
    5. using UnitySteer.Vehicles;
    6.  
    7. public class PursueRadarBehavior : PursuerBehavior , IRadarReceiver{
    8.    
    9.     public LayerMask ObstacleLayer;
    10.    
    11.     // Use this for initialization
    12.     protected void Start () {
    13.         base.Start();
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     protected void Update () {
    18.          base.Update();
    19.     }
    20.    
    21.     public void OnRadarEnter( Collider other, Radar sender )
    22.     {
    23.         Obstacle obstacle;
    24.  
    25.         if( ( 1 << other.gameObject.layer  ObstacleLayer ) > 0 )
    26.         {
    27.             obstacle = SphericalObstacle.GetObstacle( other.gameObject );
    28.             if( obstacle != null )
    29.             {
    30.                 Pursuer.Obstacles.Add( obstacle );
    31.             }
    32.         }
    33.     }
    34.    
    35.     public void OnRadarExit( Collider other, Radar sender )
    36.     {
    37.         Obstacle obstacle;
    38.        
    39.         if( ( 1 << other.gameObject.layer  ObstacleLayer ) > 0 )
    40.         {
    41.             obstacle = SphericalObstacle.GetObstacle( other.gameObject );
    42.             if( obstacle != null )
    43.             {
    44.                 Pursuer.Obstacles.Remove( obstacle );
    45.             }
    46.         }
    47.     }
    48.    
    49.    
    50.    
    51.     public void OnRadarStay( Collider other, Radar sender )
    52.     {
    53.        
    54.     }
    55.  
    56. }
    57.  
     
  20. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I kinda got it working, but I had to modify MpPursuer for that purpose, I also had to add some things here and there, are we supposed to be modifying this classes or is there a better way to do all of this?
     
  21. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Hola Ratamorph,

    (Edited to clarify)

    UnitySteer is meant to be a toolbox, not necessarily plug-and-play behaviors, since every vehicle has different requirements. Most of the provided vehicles are meant to be examples of how to implement a specific behavior using the included functions, and then you build your own vehicle by mixing and matching the provided methods.

    In the specific case of MpPursuer, it was mostly a direct translation of the original vehicle from OpenSteer, implementing solely the pursuit behavior, and did not have any obstacle avoidance written in.

    Cheers,
     
  22. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    Sweet, awesome job. It is people like you who make unity3d the best of the best.
     
  23. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Hola Arges, thanks for the reply, I got obstacle avoidance fully integrated into mpPursuer, now I'm working on getting all the different colliders in unity to work as valid obstacles, this will be a heavier change, so we'll see how that goes, I'll be more than willing to share my changes back if you are interested.
     
  24. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Sure, sounds good. Do you use git? If so the best path might be to clone the version at GitHub, which is the most recent one, and then send me your commits.

    Cheers,
     
  25. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Yes, I got the source from git, I'll let you know once I got something ready and stable, it might be a while because I'm only suppose to work on this on fridays, other than that is my free time.
     
  26. teatime

    teatime

    Joined:
    Jun 16, 2008
    Posts:
    129
    i'd be interested to see your changes too, ratamorph, though i think rather than trying to make other colliders work with radar obstacle avoidance, we might be better served by implementing containment obstacle avoidance into UnitySteer, as demonstrated here:

    http://www.red3d.com/cwr/steer/Containment.html

    i'm not a very good programmer but i'll start working on this once i fully wrap my head around what's already here. thanks for this btw, arges.
     
  27. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    That would be useful, let us know how you are doing, I'll take a look at it aswell.
     
  28. teatime

    teatime

    Joined:
    Jun 16, 2008
    Posts:
    129
    also, i don't know if this has happened to anyone else, but when i tried to use WanderRadarBehavior in my own scene, putting the Radar script on the Radar object before the sphere collider component caused the scene to crash on start 80% of the time. adding the script component after the sphere collider component fixed it, but still, it was a bit off-putting.
     
  29. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Hello everyone,

    Glad to see some lively discussion on UnitySteer. :)

    Regarding obstacle avoidance, what I really want to implement is ClearPath: http://gamma.cs.unc.edu/CA/ The algorithm is straightforward enough, and the results as demonstrated are great. I just haven't had the time, busy working on client stuff and a game of my own.

    I'm afraid I've never seen that crash teatime. Are you on Windows or Mac?
     
  30. MadMax

    MadMax

    Joined:
    Aug 5, 2009
    Posts:
    203
    I think right now radar is doing what the blue guy is doing. I have only looked at the code for a about an hour and it does not have the best documentation so I could be wrong.

    The blue guy will sometimes going into the grayarea.
     
  31. teatime

    teatime

    Joined:
    Jun 16, 2008
    Posts:
    129
    no, this is more what radar does:

    http://www.red3d.com/cwr/steer/Obstacle.html

    it only applies a force opposite the obstacle's center, hence it only really works for circular or spherical obstacles. try using it in an enclosed space and it freaks out. containment isn't perfect, but it's much more versatile.

    this clearpath stuff is really incredible, though it seems quite a bit over my head right now.
     
  32. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
  33. Pixelstudio_nl

    Pixelstudio_nl

    Joined:
    Jun 22, 2009
    Posts:
    179
    Hi, if any1 has an example of Path and UnitySteer intergrated... please :)

    I'm trying to accomplish it myself but not succussfully yet.
     
  34. atholm

    atholm

    Joined:
    Oct 10, 2008
    Posts:
    28
    Very interesting project.. thanks!
     
  35. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
  36. UnityAndI

    UnityAndI

    Joined:
    Dec 18, 2009
    Posts:
    7
    hi,

    I've dowoaded UnitySteer as well as the accompanying example. I opened the example project and added Unitysteer to the assets folder, but I'm confused about the next step.

    For example the Avoid obstacles scene.

    The Kitten instance in the Hierarchy panel has a Mono Behaviour component added to it and this component requires a Script that is not assigned yet. Which script should I add here?

    The same goes for the Proximity detector which is a child of the Kitten. Which script should I assign there? And how can you tell, also for the other scenes/examples?

    And what is the function of the Capsule in the scene?

    Confused!

    thanks for this library though :),

    Andy.
     
  37. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Hello Andy,

    Most odd - it would appear that some references got lost. I have updated the site to the latest version, you can find it here:

    http://www.arges-systems.com/files/UnitySteer.zip

    Fair warning: this is very much a work-in-progress version, and may contain issues. Do let me know how that goes.

    Cheers,
     
  38. UnityAndI

    UnityAndI

    Joined:
    Dec 18, 2009
    Posts:
    7
    ah great,

    all the examples are working now,

    thanks so much for your fast reply and action,

    Andy.
     
  39. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    AI? take a look,

    I want move my fish~~ :wink:
     
  40. webphone

    webphone

    Joined:
    Mar 13, 2010
    Posts:
    315
    I am learning unitysteer and open it in vs2008 today.

    When I add the Scripts to Unity,
    1. build am empty Boids gameobject
    2. Create a Cube, add Rigidbody, SphereCollider and Boid Behaviour script
    3. Create ProximityDetector, add Sphere Collider and Radar script which target set to Cube in Scene
    4. I created a Cube boid Preabs, drag the Cube to it

    The same structure of the sample project.

    In the scene, there are a FPC and a plane.

    I would like to see how the Cube randomly move. However, it throws nullexception error.

    But, when I close it and reopen it, it does not throw error. However, the Cube only move one time and stop.

    How should I make it work?
     

    Attached Files:

  41. Lalo

    Lalo

    Joined:
    Jan 4, 2010
    Posts:
    21
    Hi Ricardo

    Today I downloaded the two Projects from github: Examples and Unitysteer. I have problems thereof:
    1.- When I open the UnitySteer Example Project, Unity 2.6.1 asks to me for Upgrading Project, so I did it.
    2.- I select the Kitten in the Avoid Obstacle Scene, and missing scripts, so I close the unity and copy the UnitySteer folder to Assets of Example Project. I open the example project again and that's right but...
    3.- no namespace "system.linq" and similiar so I did it: http://answers.unity3d.com/questions/746/the-type-or-namespace-var-could-not-be-found-in-c. And now I've got this error:
    4.- Assets/UnitySteer/Behavor/Vehicle.cs(223,48 ) error CS0117: UnityEngine.Vector3 does not contain a definition for 'Clamp Magnitude'

    What Can I do?
    Downgrade to unity 2.0 free version?
    Downgrade to WindowsXP or just wait (and save money) for unity 3.0?

    Thanks in advance
     

    Attached Files:

  42. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Hola Lalo,

    I'm afraid the version of UnitySteer currently live is compatible with Unity 3 only. You could check out this revision for a version compatible with 2.6:

    http://github.com/ricardojmendez/UnitySteer/tree/47df3200a47367bba0016f108be28f37fb423d1e

    By clicking on the GitHub download link:

    http://github.com/ricardojmendez/UnitySteer/archives/47df3200a47367bba0016f108be28f37fb423d1e

    However, I would advise you to wait for Unity 3, as things have changed significantly (for the better!):

    http://www.arges-systems.com/articles/42/unitysteer-changes-and-re-organization

    Cheers,
     
  43. Lalo

    Lalo

    Joined:
    Jan 4, 2010
    Posts:
    21
    Gracias Ricardo

    I'll be watching for the news, and again thank you so much for your time to this project and for answer too.

    Have a nice day Ricardo :wink:

    Lalo
     
  44. SilentWarrior

    SilentWarrior

    Joined:
    Aug 3, 2010
    Posts:
    107
    Hello, I started playing with unitysteer 2 days ago, but i was using the sources from the example project. Added my code on top of it, and it was working correctly today. I updated to the new master branch, only changing the SteerForTarget with SteerForPoint and updating the layers thing, and my units seem different, they seem to be behaving a bit more dumb, sometimes one of them wanders off for 20 secs and then comes back.

    Would it be possible to update the example project, so I could see how the new changes fit in?
     
  45. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    I noticed you said you're mostly using non-monobehaviour baseclasses, so I took a look as i'm also interested in using MB's as wrappers (and doing away with 8 bazillion Unity-specific retardations), but it's mostly Utility/Helper classes and delegates. Did you change it around a bit since the initial post?
     
  46. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    SilentWarrior, do your vehicles use anything that descends from SteerForNeighbor by any chance? That change has been there for a bit, but I can't think of anything else that might be affecting you.

    The project on github *is* the latest sample project, so do let me know if any of the scenes are not behaving as you would expect.
     
  47. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Hi Duke,

    Yes, I did. The changes are detailed here, and they make UnitySteer significantly more modular than before. I'm actually gearing up to tag this latest version as 2.0, as I'm pretty close to done with the polishing.

    I believe this was the latest version that had the wrapped classes, in case you're curious: http://github.com/ricardojmendez/UnitySteer/tree/47df3200a47367bba0016f108be28f37fb423d1e
     
  48. leonardoaraujo

    leonardoaraujo

    Joined:
    Jun 3, 2010
    Posts:
    87
    Hi Arges I have the unity3d 3 pro version and I can't open the exemple project (unity3d failed to open this project "Creating directory error")
    Do you already seen this?
     
  49. leonardoaraujo

    leonardoaraujo

    Joined:
    Jun 3, 2010
    Posts:
    87
  50. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Hi Leonardo,

    Yes, that is the latest version of the sources, but I'm afraid I've never seen that error. I take it you're also getting the latest version of the examples themselves from here, correct?