Search Unity

UnitySteer - steering library for Unity

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

  1. leonardoaraujo

    leonardoaraujo

    Joined:
    Jun 3, 2010
    Posts:
    87
    Hi Arges one question, I've downloaded the angryAnt path tool in unit 3 and it did not compiled right... Do you also use path in unitySteer? You had fixed the Path?
     
  2. Eric

    Eric

    Joined:
    Nov 17, 2008
    Posts:
    20
    Hi leonardo,

    I fixed this error and another error (when Unity writes its cachedata if you close the project) by creating the necessary directories by hand. It seems that you need to create the following directories before you can open the project without problems:

    - "\Library\metadata" and
    - "\Library\cache"

    Greets Eric
     
    Last edited: Oct 19, 2010
  3. dannox

    dannox

    Joined:
    Oct 20, 2010
    Posts:
    12
    Hi,
    I use snow leopard and I have the same problem. I create the directories you mentioned and give the permission,
    but it still give the error:

    Creating directory library/metadata/00 failed
    :-|

    cheers,
    daniele

     
  4. Eric

    Eric

    Joined:
    Nov 17, 2008
    Posts:
    20
    I'm working with Windows XP. I dont have a Mac available to test this. Maybe you could try to create the necessary subfolders too. This might be a writing permission mismatch in the source files.

    by the way: Thank you so much Arges to these great components! After trying to create some steering behaviors myself I was glad to find your package which saved me a lot of work.
     
  5. Eric

    Eric

    Joined:
    Nov 17, 2008
    Posts:
    20
    Today I wondered why some of the generated colliders of spherical obstacles have a different radius than their attached collider. (This is visible in the Sceneview by the red wireSphere when using SteerForSphericalObstacle) At a closer look i saw that the only difference is the rotation of the spheres.

    A look into the code showed that the radius of the new sphereCollider is given by the boundingbox of the collider (via collider.bounds.extents). [Obstacle.cs line 101]

    As shown in this Thread by Eric5h5 the boundingbox doesn't rotate, so the radius gets bigger than expected if the rotation is between 90 degrees intervals.

    As a little improvement I would change the code to get the radius directly from the sphereCollider if there exists one in the collider Object.
    [this code replaces Obstacle.cs line 100 - 112:]
    Code (csharp):
    1.  
    2. try
    3. {
    4.     SphereCollider sphereCollider = collider as SphereCollider;
    5.     currentRadius = sphereCollider.radius * Mathf.Max(sphereCollider.transform.localScale.x, sphereCollider.transform.localScale.y, sphereCollider.transform.localScale.z);
    6. }
    7. catch
    8. {
    9.     // Get the maximum extent to create a sphere that encompasses the whole obstacle
    10.     float maxExtents = Mathf.Max(Mathf.Max(collider.bounds.extents.x, collider.bounds.extents.y),
    11.                                  collider.bounds.extents.z);
    12.  
    13.     /*
    14.      * Calculate the displacement from the object center to the
    15.      * collider, and add in the maximum extents of the bounds.
    16.      * Notice that we don't need to multiply by the object's
    17.      * local scale, since that is already considered in the
    18.      * bounding rectangle.
    19.      */
    20.     float distanceToCollider = Vector3.Distance(gameObject.transform.position, collider.bounds.center);
    21.     currentRadius = distanceToCollider + maxExtents;
    22. }
    23.  
    I didn't find a way to set the radius correctly for SphericalObstacles with other Colliders attached, maybe someone else could find a way to get this working too.

    Greets
    Eric
     
    Last edited: Oct 28, 2010
  6. Arges

    Arges

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

    There are two ways of doing this:

    1. Don't mark the whole object as an obstacle. Instead, mark a separate invisible object which only contains a sphere collider as an obstacle; or
    2. Add a SphericalObstacleData behavior to override the bounding sphere radius and center.

    Cheers,
     
  7. Eric

    Eric

    Joined:
    Nov 17, 2008
    Posts:
    20
    ok I see, thank you!
     
  8. gl33mer

    gl33mer

    Joined:
    May 24, 2010
    Posts:
    281
    Am I correct in assuming all examples in UnitySteer are C#?

    Any tutorial/example for UnityScript users?

    Thank you.
     
  9. gl33mer

    gl33mer

    Joined:
    May 24, 2010
    Posts:
    281
    Just as a little inspiration - here's a few games by radiangames (a 1 man team as far as I know) - for Xbox Live Indie -

    They all seem to rely heavily on different types of steering behaviours, thought you'd find it interesting:

    The Inferno Trailer.

    The FireBall trailer

    The Fluid trailer.

    There's also an interesting article on gamasutra regarding RadianGames sales over the past 6 months on XboxLive
     
  10. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    All the UnitySteer behaviors are written in C#. The examples from the sample project contain no custom code I can recall beyond the pre-created behaviors, and merely configure them via the published properties.

    I'm not a UnityScript user myself, but perhaps others can help.

    Cheers,
     
  11. gl33mer

    gl33mer

    Joined:
    May 24, 2010
    Posts:
    281
    Thanks Arges.


    Thanks for answering.
     
  12. arbbot

    arbbot

    Joined:
    May 2, 2010
    Posts:
    74
    Hey Ricardo,

    Wanted to check with you if UnitySteer will work with Unity 3.1. Are there any limitations or known issues?

    Cheers!
    -arbbot
     
  13. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    it does work on unity 3 :).
     
  14. arbbot

    arbbot

    Joined:
    May 2, 2010
    Posts:
    74
    Nice. Thanks @Fishman92 !
     
  15. gl33mer

    gl33mer

    Joined:
    May 24, 2010
    Posts:
    281
    Downloaded UnitySteer from the assetstore.

    Seems to import fine.

    Tried getting the Example zip from Github.

    Added the necessary metadata and cache directories but still all scripts seem to be missing from the objects.


    I saw your comment pointing to a file on arges that was supposed to fix the examples - that is now broken.

    Are the examples now broken due to the new UnitySteer?

    Help appreciated.
     
  16. gl33mer

    gl33mer

    Joined:
    May 24, 2010
    Posts:
    281
    Ok.

    Getting UnitySteer from the AssetStore is fine - though it doesn't seem to have the project file with all the examples.
    Getting the examples from Github - broken examples.

    Getting the project from here:http://www.arges-systems.com/articles/48/unitysteer-20-released
    Seems to work - It's probably not the latest branch (though I'm not sure) - but the examples seem to be working flawlessly :) on Unity3.1.0

    Thanks, finally some flocking action
     
  17. gl33mer

    gl33mer

    Joined:
    May 24, 2010
    Posts:
    281
    Wow.

    It's great.

    Thanks for the great package.
     
  18. BorisB

    BorisB

    Joined:
    Dec 8, 2010
    Posts:
    13
    Hello Arges!
    I would like to use UnitySteer in a commercial non-opensource game. Can I do that?
    If yes , what should I do? (mention author,include license, etc).

    P.S. Great work
     
  19. Arges

    Arges

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

    No reason you can't. You can read more about the MIT license here. The even shorter version is: take it, use it, not our fault if it burns down your house. The only requirement is that you include the copyright notice and license for UnitySteer, and since it uses code from OpenSteer and OpenSteerDotNet, for those two as well. See the included LICENSE.TXT for details.

    Cheers,
     
  20. BorisB

    BorisB

    Joined:
    Dec 8, 2010
    Posts:
    13
    Thanks for the quick answer.

    Cheers
     
  21. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    My pleasure, I was around. Glad you're finding it useful - I'd love to see what you do with it.

    Cheers,
     
  22. pickledzebra

    pickledzebra

    Joined:
    Feb 25, 2010
    Posts:
    33
    Hi Ricardo,

    Wonderful package! It's entertaining as well as easy to learn from.

    One thing I noted - in trying to merge unitysteer with some other examples I'm learning from, I end up with 2 CharacterMotor.cs files. When I try to use the one that looks to be the more standard script with that name, I end up with errors such as:

    Do you know a quick way to fix this? thanks!
     
  23. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Yes, you don't need to use the two scripts from the Utils directory on the example project files, just the ones from "Assets/Scripts", so feel free to remove those two .cs files to avoid clashing with the standard assets. Alternatively, you can just import the version from the Asset Store, which contains only the required scripts.
     
  24. pickledzebra

    pickledzebra

    Joined:
    Feb 25, 2010
    Posts:
    33
    Thank you so much. Great stuff. Great fun!
     
  25. nikemerlino

    nikemerlino

    Joined:
    Jul 2, 2008
    Posts:
    66
    Hi Ricardo,
    Thank you, great work!
    Can you explain us how to use the two classes (SteerForPathTrivial, SteerForPathPredictiveTrivial) in the new version?
     
  26. CWM

    CWM

    Joined:
    Jan 11, 2011
    Posts:
    29
    Hi I'm new to Unity, but want to experiment with UnitySteer.. I've downloaded the package and examples from GitHub. However the examples don't seem to work. I get the error "The referenced script on this Behaviour is missing! Assert in file ..\..\Runtime\Mono\MonoBehaviour.cpp at line 1624" Thanks for any help you can provide. The package looks very promising!
     
  27. CWM

    CWM

    Joined:
    Jan 11, 2011
    Posts:
    29
    I got it working by coping the UnitySteer folder to Assets of Example Project as suggested by Lalo. Before, I had the examples in the UnitySteer primary folder.
     
  28. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
  29. Atreïde

    Atreïde

    Joined:
    Jan 22, 2011
    Posts:
    3
    Hello,

    I feel Unitysteer is not working as it should in case of multiple obstacles.
    But maybe I’m wrong and miss something about this library or the given samples.
    I got the latest library from git and updated the « showcase » asset, when I run the test cases where two items are going to reach their target (Test cases folder), one of them . (the white right bottom capsule) is always hitting the red obstacle.
    What I understand, the goal is to avoid the other moving capsule AND the « locked » red item (obstacle) ...Am I wrong ?
    Here a screenshots about the issue.





     
  30. Patyrn

    Patyrn

    Joined:
    Feb 17, 2011
    Posts:
    57
    I experience the same issues. I tried tweaking weight values and such, but it seems to always either steer through the other capsule or one of the obstacles.
     
  31. MitchStan

    MitchStan

    Joined:
    Feb 26, 2007
    Posts:
    568
    Have your tried implementing dynamic collision avoidance using RVO2 from the folks over at UNC. There is already a Unity project - link at the UNC cite.

    It would be a fabulous addition to UnitySteer.
     
  32. Minassian

    Minassian

    Joined:
    Nov 22, 2010
    Posts:
    40
    Hola Ricardo.
    I'm having issues extending UnitySteer. Right now I'm dealing with them by modifing the UnitySteer base classes, but this is not the most maintaneable way in the world and I was wondering if it could be done in some other way.

    Radar.cs: I need to change the way if fetches the Vehicle component, because in my game most of the times colliders are not in the root GameObject, but on child GameObjects. Overriding Awake() and FilterDetected() was the first choice, but since _vehicles is private I could not copypaste the changed method.
    I ended up with a
    Code (csharp):
    1. virtual protected getVehicle(Transform)
    2. {
    3.     return vehicleTransform.root.GetComponent<Vehicle>();
    4. }
    that gets called both from Awake() and FilterDetected().
    Does it make sense to add this virtual method to the base implementation ?:
    Code (csharp):
    1. virtual protected Vehicle getVehicle(Transform vehicleTransform)
    2. {
    3.     return GetComponent<Vehicle>();
    4. }
    I'm working on a framework to use states with Behave and UnitySteer, and for it I need to add Steering behaviours dinamically to a GameObject.
    For this, I had to change two things in the base classes.
    Steering.cs: An Awake() functions that initializes the _tick variable if its null.
    Vehicle.cs: A setter for Steering.
    Is there any way to decouple my code from the Steering classes ?
     
  33. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
  34. SteveK

    SteveK

    Joined:
    Mar 2, 2011
    Posts:
    25
    I ran into a problem where I wanted to implement Start in my Steering behavior, but that would hide Steering.Start. The solution is to make it virtual so it can be overridden by user code. I think this should be done for all implemented MonoBehaviour functions that are on classes intended to be used with inheritance (Steering, Vehicle, Radar).

    Steering.cs
    Code (csharp):
    1.  
    2. protected virtual void Start()
    3.  
    User code:
    Code (csharp):
    1.  
    2. protected override void Start()
    3.  
    Thoughts?
     
  35. Minassian

    Minassian

    Joined:
    Nov 22, 2010
    Posts:
    40
    Funny that this happened to me at the very exact same moment I receive the notification mail for this post.
    I have 5 UnitySteer files modified right now, I just don't understand .net restrictions.
     
  36. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    Hey Minassian, I'm having to also add Steering behaviours dinamically to a GameObject in my game.

    Could you post your changes to Steering.cs and Vehicle.cs to allow this ?

    Thanx !
     
  37. Minassian

    Minassian

    Joined:
    Nov 22, 2010
    Posts:
    40
    Hey invader.
    I just changed the access restrictions as I needed them for variables, nothing that anyone can't do on the fly.
    I don't think my changes will be suited for every project, but if you still want them add me to skype and I'll drop 'em to ya.

    Cheers.
     
  38. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    ( if anybody else is having the problem of adding the AutonomousVehicle and behavior components through code)

    1) add the behaviors first and then the AV, due to the AV caching the behaviors on init.

    2) Thanks Minassian, I think I got it to work following your suggestion
    which didn't work for me in the awake function but adding below code to Start function of Steering.cs did:

    if ( _tick == null )
    {
    _tick = new Tick ();
    }
     
  39. vr28

    vr28

    Joined:
    May 7, 2011
    Posts:
    2
    Hi,
    I am just trying to use unitysteer. the gameobject is jumping the obstacle. Can anyone help me out. Thanks
    [/URL] Uploaded with ImageShack.us[/IMG]
     
  40. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    How would i smooth the rotations?
     
  41. Arges

    Arges

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

    There was an old bug that I didn't notice until recently where rotation smoothed was basically borked. I fixed it about a month ago in the experimental branch, but have not yet merged the fix into development or master. I might cherrypick that commit and release a 2.3 in the next couple of weeks, but for now I'm a bit swamped and the experimental branch has diverged enough from development that it'll take some testing.

    Cheers,
     
  42. Meltdown

    Meltdown

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

    Any chance you can look at my Question on UnityAnswers.

    Also on thispage on your site, you mention the line of code..

    var steer = yourAgent.GetComponent();

    What exactly does the object 'yourAgent' need to be, I am attaching the SteerForPathSimplified script to a cube in my scene. Is that right, sorry its all a little confusing.
     
  43. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    That's pseudocode, where yourAgent would be whatever variable your storing the reference to your agent at (in this case, a reference to your cube's gameObject).
     
  44. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    Haha, thanks Arges,

    Was trying to figure out if it was some sort of Psuedo code or not, will try it out
     
  45. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    EDIT : I have it working now.

    I attached a SteerForPathSimplified Script to my object and it seems to be working now.

    Which scripts would you attach to a car to make it go around a track and carry on along the path even if it got bumped/turned around the wrong way?

    Thanks for the help.
     
    Last edited: May 30, 2011
  46. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    Ok awesome, I have it working and my AI cars are going around the track like a dream. Wow I am so impressed :p
    I have one final issue to resolve, when I initialise my Vector3Pathway with IsCyclic = true...

    Path = new UnitySteer.Vector3Pathway(GetVectors(), 0.5f, true);

    I get an Indexoutofrangeexception.

    Looking at the method Initialize (IList<Vector3> path, float radius, bool cyclic)
    What doesn't make sense to me is why if isCyclic = true you would increment pointCount, then try to access the path element in a foreach loop with pointCount when that element can never exist?

    Is this intended or am I missing something?

    Thanks
     
  47. Sollthar

    Sollthar

    Joined:
    Feb 11, 2010
    Posts:
    486
    Just got recommended your great package! Thanks for all your work.

    I was wondering though, is there any sort of manual on how to set up a scene and what each script actually does? Some kind of quickstart guide? I can't seem to find anything. Apologies if it should be obvious.
     
  48. mmuller

    mmuller

    Joined:
    Nov 23, 2010
    Posts:
    92
    Hi Ricardo,

    I have started utilising your wonderful UnitySteer in my new iOS/Android shooter - works well for my 'stupid' enemies in the fist few levels, however on some of the more advanced enemies that are set to target the player (naturally) and steer towards them and start firing. The problem I have is that if they achieve their goal and destroy the player I need to reset the Target of each one to the newly instantiated player.

    I tried creating a new method in SteerForTarget:

    Code (csharp):
    1.     public void ReAttach()
    2.     {
    3.         Transform Target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
    4.     }
    And then calling that method when instantiating my new player, strangely though they don't appear to then follow the new player.

    If I select the player in the editor it works fine and they start following again, so what am I missing in my code to do this automagically ?

    Best Regards,

    M
     
  49. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    You seem to be assigning the value to a local variable scoped to that ReAttach method, not to the SteerForTarget property.
     
  50. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    There are no step-by-step tutorials. You may want to look at how the vehicles are set up on the examples project, and review the description of how an agent is constructed here: http://www.arges-systems.com/articles/42/unitysteer-changes-and-re-organization/