Search Unity

UnitySteer - steering library for Unity

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

  1. makan

    makan

    Joined:
    Jan 8, 2011
    Posts:
    342
    Very cool :D
     
  2. mmuller

    mmuller

    Joined:
    Nov 23, 2010
    Posts:
    87
    Ricardo,

    Tried it as both Transform Target which I realise was a local var and also as Target = ... neither worked...

    However, a quick hack to the CalculateForce method of checking for null and then reassigning the newly instantiated object works a treat :D

    Code (csharp):
    1.     protected override Vector3 CalculateForce()
    2.     {
    3.         if (Target == null)
    4.         {
    5.             Target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
    6.         }
    7.        
    8.         return Vehicle.GetSeekVector(Target.position);
    9.     }
    Obviously this will only work when I only need to follow the player - I will return to my reattach method if the need arises ;)
     
  3. vahi2008

    vahi2008

    Joined:
    Oct 1, 2010
    Posts:
    321
    hiii,

    i downloaded the zip file and opened the scene , i am getting these errors

    http://www.image-share.com/ijpg-758-84.html
    http://www.image-share.com/ijpg-758-85.html

    Asset is dirty after import?
    Failed to create cache directory for asset Assets/Models
    Failed to create cache directory for asset Library/InputManager.asset
    Path mapping for Asset with GUID bf8d91bcf6ae141bdb335fddb6967d55 is missing! Cleaning up.

    so many of them...plz advice why these are coming , whats wrong ??
     
  4. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,232
    Hi Ricardo,

    Great work on UnitySteer.

    I'm trying to get my head around how to reconcile UnitySteer with pathfinding (using Detour) and animation-driven motion. I've got something that looks OK by using UnitySteer's forces to alter the animation playback speed, which in turn generates the movement deltas...

    What I'm slightly stumped on is how to detect when the vehicle is trying to turn, because I've got dedicated turn animations that I want to play in those situations. Is it sufficient to just look for forces that are pushing strongly to the left or right of my character, or will that not be accurate?
     
  5. jfabris

    jfabris

    Joined:
    Sep 17, 2011
    Posts:
    12
    Hi,

    I am using UnitySteer 2.0 in a tank game I am working on.

    I've got a tank going to a target, with a building in a way. Problem is, the tank goes over the building instead of around it. What can I do about that?

    The tank has:
    RigidBody
    Character Controller
    Autonomous Vehicle
    Steer for Target
    Radar Ping
    Steer for Spherical Obstacle Avoidance
     
  6. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    667
    Arges, thanks for such an excellent library.

    I've been playing with it, and made some bits of customization.

    In my case, the IsPlanar property, should fix the Z axis, instead of the Y. The first thing I tried was to add rigibodies to my boids and use the constrains, but it didnt work. So I went ahead and changed some bits on the code.

    I've found however, that the Z value (now the IsPlanar fixed axis) slowly erodes as the boids move through the space. I've tried to isolate the cause of this to one of the behaviours without luck. I have no rigibodies, so its not physics.

    Any ideas where the value affection may be coming from?
     
  7. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Last edited: Jan 14, 2012
  8. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    667
    That indeed solved it!
    Thank you very much Arges. Outstanding work!
     
  9. beardkey

    beardkey

    Joined:
    Jan 10, 2012
    Posts:
    7
    Hi everyone. UnitySteer seems pretty great, but looking through the code I have one question - is there an easy way to make something move in the x,y axis with rotation around z? Right now everything seems to be set for x,z with rot around y.

    I'll keep looking in the meantime. Thanks!
     
  10. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,430
    Hi,

    I am building some pits for my racing game. When I enter the pits, I send 4 mechanics each to one wheel of the car.
    The problem is the one mechanic always gets stuck (the one going to the rear right tyre). He just runs into the vehicle, he doesn't really go around it. He has RadarPing, Autonomous Vehicle, SteerForNeighbourAvoidance, SteerForSphericalObstacleAvoidance and is using SteerForTarget to get to the side of the tyre.

    I've tried almost every setting I can. Is there any way to make him turn sharper to get around the vehicle?

    This is a screenshot of the mechanic running for the right rear tyre, he just gets stuck there.



    Thanks
     
    Last edited: Feb 27, 2012
  11. OmniverseProduct

    OmniverseProduct

    Joined:
    Feb 26, 2012
    Posts:
    1,569
    I'm pretty sure I know the answer to this, but this will work with two wheeled vehicles without modification right? I'm learning Javascript and currently don't know C# so I can't do any modifying. Just thought I'd make sure.
     
  12. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,430
    Four wheels or two wheels the mechanic still needs to get around the body of the vehicle. That is the problem.
     
  13. OmniverseProduct

    OmniverseProduct

    Joined:
    Feb 26, 2012
    Posts:
    1,569
    Good enough for me. I'm not planning on having a mechanic move around the vehicle, so to speak anyway. When the mechanic works it's like a repair option on an rpg. All the player has to do is hit a certain button and it works automatically. I know it's not the most realistic thing, but this isn't really a realistic game. In fact I had nightmares when I pictured it in my head, lol. It's a combat racer, btw.
     
  14. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,430
    My temporary solution to the problem for now was to create a set of waypoints around the vehicle. As the mechanic arrives at these, I move him to the next waypoint. I found the behaviour for SteerForTarget better suited than SteerForPathSimplified in this instance.
     
  15. why789

    why789

    Joined:
    Sep 23, 2011
    Posts:
    184
    How would I get the UnitySteer to follow a path given by AngryAnt's Path?

    I see people talking about using the pathfollower script but I can't find that in the scripts? Only path simplified or path trivial, etc.

    Thanks,
    why789
     
  16. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
  17. why789

    why789

    Joined:
    Sep 23, 2011
    Posts:
    184
    Thank you for your quick response!

    How would I get the IList?

    The only thing I can see that might help is the Segments property in the path class however that returns as a ReadOnlyCollection and I can't quite figure out how to iterate through it (or get it into an IList)

    Thank you very much :)
    why789
     
  18. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    That would depend entirely on the pathfinding system you're using. I am not currently using Path (no pathfinding at all on our game) but I recall it raised an event when it was done searching and sent you the list of points, which is where you'd get it from.
     
  19. why789

    why789

    Joined:
    Sep 23, 2011
    Posts:
    184
  20. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    You should probably look into what that Path class contains. You can get a list of points from it.
     
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    May I ask what is the best entry point into using UnitySteer?

    I am interested in using UnitySteer for NPC Ships moving in 3D volumes (Space FlightSim) and I am interested in maintaining code that could be used on iOS.

    The two post that have my knickers in a twist about which one to use are this one:
    articles/274/unitysteer-2-2-released/
    ... which seem to indicate that this is the most recent stable release,
    and this one:
    articles/573/unitysteer-autonomous-vehicle-biped/
    which seems to suggest using the development branch.

    Is there a "best suggestion"?

    I'll be wading in, arms bare, either way, but any hints to cut down the start-up time would be great.
     
  22. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    It depends with how comfortable you're with looking at code.

    If you don't mind reading pseudo-code and implementation notes, go with 2.5b1. Just a couple of days ago I merged the development branch into the master and marked it as 2.5b1, to get it ready for release: https://github.com/ricardojmendez/UnitySteer/zipball/v2.5b1 and read the recent articles on the site: http://www.arges-systems.com/articles/category/unitysteer/ as well as the release notes. I'll update the UnitySteer example project for 2.5b1 on Monday.

    Alternatively, you can check out the UnitySteerExamples https://github.com/ricardojmendez/UnitySteerExamples which still has the submodule reference to 2.2. The examples should be more stable, and you're more likely to find references on the forums to how people have dealt with their own implementations.

    The documentation notes are a bit scattered and unstructured right now, but will hopefully improve gradually over the next few weeks after we release.

    Cheers,
     
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Thanks for the response.

    I've been playing with the sample project. I downloaded it after I posted (3 days ago) and I'm making some headway. I'm still unclear which property influences what in some cases (ships turning on a dime to follow the target or rigidbody collisions messing up movement after impact), but I'm slowly beginning to see how things are hanging together.

    I have snagged the 2.5b1 code and will look at the updated example project tomorrow or so...
     
  24. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,430
    Hi Ricardo,

    It's great to see the upcoming updates to UnitySteer and looking forward to them.

    One of the problems I'm having is on SteerForTarget my agents always get stuck when they get to a cube shaped obstacle.

    Would I need to implement my own SteerForCubeObstacleAvoidance class or will the new updates correctly navigate around a cube to the target?

    Cheers
     
  25. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    The "turning on a dime" issue was a bug with the old 2.2 code, and it is (as far as I can tell) fixed on the 2.5b1. I do agree, it needs more extensive documentation, since its own nature as a toolkit is a double-edged sword: it's very flexible on what you can build, but requires some digging in before you can do so.

    Do let me know how the 2.5b1 experiments go. Cheers,
     
  26. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    You can just treat a cube a a spherical obstacle. I'd recommend looking at the couple of example scenes on UnitySteerExamples 2.5b1 which deal with spherical obstacle avoidance to see one way of setting it up (it will of course depend on what your vehicle ends up being like).
     
  27. joeyxiong

    joeyxiong

    Joined:
    Dec 13, 2011
    Posts:
    10
  28. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Actually, that page gives a very good description of how to do it. I recommend you look into the SteerForNeighbors subclasses, particularly SteerForSeparation. You can get an initial version going by adding SteerForSeparation and SteerForPoint, as Mr. Reynolds describes, but bear in mind that:

    - You'll need to update the target point yourself
    - SteerForPoint does not slow down as it approaches the target. To do that, you need to change the second parameter on GetSeekVector, or use this version: https://github.com/ricardojmendez/UnitySteer/blob/development/Behaviors/SteerForPoint.cs

    You can use that one to make a SteerForFollow, which does not receive a point but a transform and continually seeks its position (UnitySteer already has a SteerForPursuit, but that one doesn't merely follow, it tries to predict where another vehicle will end up).
     
  29. joeyxiong

    joeyxiong

    Joined:
    Dec 13, 2011
    Posts:
    10
    I write a sample myself, and also tried this one:
    http://rocketmandevelopment.com/2010/10/29/steering-behaviors-leader-following/
    but it's not good as red3d's java demo
     
  30. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    I can't see Mr. Reynold's example right now - I have the java plugin disabled - but this is how a quick implementation of what I described above would look like for non-planar vehicles:

    http://www.arges-systems.com/articles/590/quick-steertofollow-example/

    Update: tweaked the parameters a bit to give the leader a shorter turn time, so that we get quicker turns and more interesting movement where the followers get disrupted.
     
    Last edited: Apr 13, 2012
  31. joeyxiong

    joeyxiong

    Joined:
    Dec 13, 2011
    Posts:
    10
    I updated the sample project, and got a error "Monobehaviour has unknown format!: Base Type:MonoBehaviour ByteSize:-1 MetaFlag:32768"
    The last behaviour of follower is missing.
     
  32. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Rigidbodies...

    I have been experimenting with non-kinematic rigidbodies and if they have a collision and react to the collision force, it seems that the AutonomousVehicle doesn't ever overcome the forces involved. Looking at AV.cs it seems that non-kinematic rigidbodies are moved with MovePosition. I am assuming that what is happening is the collisions are adding a force to the rigidbody which results in a rigidbody.velocity which is never negated and the AV.MaxForce and AV.MaxSpeed are fighting this rb.velocity?

    Admittedly I'm still fussing with 2.2...

    Am I on the correct track?
     
  33. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,430
    Have you tried the Override Rigidbody Mass option?
     
  34. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Yes, actually I have.

    What I surmise is that the impact between the rigidbodies is adding force to the Autonomous Vehicle (AV) which is causing the AV.rigidbody to have rigidbody.velocity. Override Rigidbody Mass doesn't seem to do anything. The test I have done is print the AV.rb.velocity every second, and before a collision the rb.v is (0,0,0), after the collision the rb.v has a constant value until there is another collision to add force and change the rb.v to a new constant.

    This makes sense as the choices for movement from the AV.cs seems to be:
    _characterController.Move(delta);
    transform.position += delta;
    _rigidbody.MovePosition (_rigidbody.position + delta);


    ... so there are no forces involved.

    The only overt solution is to set the AV.rb to isKinematic, so it ignores the physics in the collision, which is not really what I want. I don't feel like simulating impact behavior.

    Trying to use delta to add force seems like it could be a tricky balancing act.

    What I could do is try to dampen any rb.v over time, which might work fine.

    I don't get a lot of time to experiment, but I think I'm on the right track.

    [edit]

    Which is, just to be clear, simply cranking up the Drag and Angular Drag... I was just afraid to monkey with things too much until I knew what was going on... And yes, basic experimentation shows that simply setting Drag and Angular Drag to 1 provides enough dampening that the AV quickly overcomes the rb.v that's been created from a collision.
     
  35. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    The only thing this meant to do is have the vehicle calculate its vectors based not on the mass configured for the rigidbody, but on the internal mass value that is set for the vehicle.
     
  36. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Your assessment above is correct. I initially experimented with moving the vehicles with rigidbody.AddForce, but didn't like the results at all. While they could work in some cases (say, you're doing a Newtonian vehicle for a spaceship), it requires the vehicle to interpret the force being returned differently. It didn't seem to be worth the effort to maintain for such a specific case, but after 2.5b1 it could be yet another offshoot of TickedVehicle.
     
  37. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Can't wait to get the chance to really look at 2.51b. I discovered a piece of "found time" to play in, and fooled with the existing set up rather than getting the new version going, but it's doing great so far...

    Next is working thru the settings for avoidance...
     
  38. joeyxiong

    joeyxiong

    Joined:
    Dec 13, 2011
    Posts:
    10
    Use grid A* for path finding, combine flocking and path follow behavior, move the units to "X", how to separate the units into two path?
     
  39. n8

    n8

    Joined:
    Mar 4, 2010
    Posts:
    147
    I am building a game that makes use of vehicles "hovering" a set distance from the ground. Is there a script that I can build off of to apply this functionality? I tried using the "isPlanar" variable on the AutonomousVehicle but that allows the vehicle to be pushed up when the terrain changes, but then never really comes back down. Any Ideas?
     
  40. jpeele

    jpeele

    Joined:
    Apr 5, 2012
    Posts:
    7
    I'm working on creating a RTS framework within unity. It uses UnitySteer and Aron's A*Project as the key navigation components. I plan on writing up some tutorials on how to integrate the two, but I have to figure out how to to begin with. I was wondering if has any experience or pointers on how to go about integrating the two. Right now I have sketchy way of getting them to work together, but I hope to improve my frameworks performance as I go along. Again if anybody wants to help out or to follow along with the progress please pm me, I want this to be a tutorial for the community so making it with the community would be awsome. Here's the latest progress update and how it looks so far:
    http://youtu.be/V82gYH5bjt0
     
  41. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,430
    I upgraded my project to 2.5, and changed from the RadarPing script to Radar. I've tried lots of settings but no matter what my NPC still gets stuck trying to get around a square collider on SteerForTarget. How do I 'treat' the cube as a spherical obstacle?

    Is there any other setting you suggest?

    Thanks
     
  42. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    You may need to look at the forces that are influencing the unit, and the physics. I have a ship that, if it is too close to an object, will not be able to turn to avoid it. Then, once it's bumped up against the obstacle, doesn't have enough force to turn around to fly away, so it just bumps along being stick to the surface of the object...

    My proposed (internal) solution, is to have some sort of behavior state machine or tree and when the unit is stuck, to change it's behavior. This makes sense... "Enemy! GO GET IT!" <bump> "D'oh, stuck!: GET UNSTUCK!" <free> "Enemy!.... " etc.
     
  43. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    For Example:



    This is from several weeks ago, and I have not had a chance to play with it for quite a while, but this gets the idea across. The seeker needs to be able to change behavior when it's stuck to the surface of the sphere, then once broken free, needs to return to the seeking behavior.
     
  44. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,430
    That of course makes sense but you'd hope that it being called UnitySteer it would be able to steer around obstacles easily :)
     
  45. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Yes, perhaps, but I feel (and people can correct me if I have the wrong impression) that UnitySteer is steering behavior rather than AI, per se. There are a number of situations that UnitySteer can steer for, and a number of forces that can be set and adjusted that give new behavior to the Vehicles. But UnitySteer would need an AI Machine of some sort to change, for example, between "Seeking" and "Fleeing" based on a given set of circumstances: Health 25-100 "Seek"; Heath 1-25 "Flee"; - So it's not inconceivable that a Vehicle would have "Seeking", "Fleeing", "Searching" even "Unsticking" if the forces are not enough to avoid a situation. In the case of my Vehicle, I feel that the turn forces and seeking acceleration are not in the correct balance to "Unstick" the Vehicle. I imagine if I set the turn force high enough to "unstick" it from the sphere... it might turn to quickly when in combat. So - if the vehicle is balanced for combat, it will just get stuck. I can think of this in a car game where the Vehicle misses a turn when avoiding a team-mate and it ends up on the grass... its behavior may have to change from "Racing " behavior to "Getting back on the Track" behavior even by going into reverse and doing a 3 point turn to get oriented properly.
     
  46. n8

    n8

    Joined:
    Mar 4, 2010
    Posts:
    147
    I agree with @Little Angel. UnitySteer is a way of implementing the behaviors you want. You still need some other system to determine what scenario you are in and then flip on or off certain behaviors. There are certain instances where Unitysteer contains all of the "AI" that you need for a vehicle. for example, a missile, the steerfortarget (or steerforpoint) behavior would be sufficient for the "AI" in that all the missile ever needs to do is just get to that target and slam into it. I have been able to stack several behaviors onto a vehicle and get pretty close to something that resembles AI, but really all you are getting is a single minded behavior that won't really react to the environment very well.
     
  47. jackpile

    jackpile

    Joined:
    Apr 13, 2011
    Posts:
    27
    Is there ANY documentation on how to effectively use UnitySteer 2.5? Or is the only method to spend hours reading the code and experimenting with examples? This looks really fabulous but impossible to truly make effective use of without good documentation. It's a real shame. I guess you get what you pay for, eh?
     
  48. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    Bit of a delayed reply, but that is correct - Hairy Tales uses Angry Ant's Behave to toggle/tweak the behaviours depending on the situation, but any other mechanism will do.
     
  49. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
    There are no tutorials right now, mostly because I just don't have the time, but experiment with the examples would actually be the preferred way to get acquainted with the components. It's more of a toolkit, and you'll need to be familiar with the options in order to be able to simulate your desired behaviour (which changes from game to game).

    I do plan to create a few tutorials once Hairy Tales has been released and I've wrapped 2.5 (which is currently beta) but just can't spare the time right now.

    Cheers!
     
  50. n8

    n8

    Joined:
    Mar 4, 2010
    Posts:
    147
    Hey everybody,

    I am having a terrible time trying to get unitysteer working to avoid obstacles. I can get most other behaviors to work, but not neighbor avoidance or obstacle avoidance. I am using the latest from the dev branch. here is an example of what I am seeing. It seems that the radar is picking up the obstacle, but it is failing to register an intersection, and so never applying the forces necessary to avoid the collision. Since no avoidance happens the vehicle just slams into the collider and comes to a stop. Any ideas? do I have something setup wrong? Thanks in advance for any help

    Also, the separation behavior doesn't seem to be working either. many times, vehicles will be occupying the same space at the same time .
     

    Attached Files:

    Last edited: May 23, 2012
unityunity