B4A Library [Lib] Steering Behaviors

Discussion in 'Additional libraries, classes and official updates' started by Informatix, Jun 6, 2013.

  1. Informatix

    Informatix Expert Licensed User

    This library will bring life to the animated characters of your game by giving them autonomy. It is based on the Craig Reynold's article: Steering Behaviors For Autonomous Characters.

    Let's imagine a game where a cat pursues a mouse. You have to write the code to move the mouse, to move the cat and to take the right decisions for both: the cat wants to catch the mouse, the mouse wants to evade the cat. This library will do this very easily. You create two vehicles: a cat and a mouse, with an initial location, a maximum speed, a mass, etc. Then you add their behaviors (with the Steer function) in the main loop: Pursue for the cat, Evade for the mouse. You apply these behaviors with Cat.Move and Mouse.Move, and that's it. You're ready to watch them running around.

    You have many behaviors available: Align, Arrive, AvoidObstacles, AvoidVehicles, Cohere, Evade, Flee, FollowPath, Pursue, Seek, Separate, View, and Wander. By combining them, you can create new behaviors like Flock, FollowLeader, StayOnPath...

    Starting from version 2, the library is released as a donationware. That means: if you want to use it in your application, please donate something by using the link in my signature. I'll send you the file as soon as I receive your donation.

    You can donate what you want, from one dollar to one million dollars (for such an amount, you'll be my friend forever ).
    I don't do that to earn a lot of money, just to be rewarded for my work (and I probably won't earn a lot of money this way ;-)).

    Thanks in advance for your support.

    Version 1.1 Free
    11 behaviors: Align, Arrive, AvoidObstacles, Cohere, Evade, Flee, FollowPath, Pursue, Seek, Separate, and Wander.
    11 examples.

    Version 2.3 Donationware
    13 behaviors: Align, Arrive, AvoidObstacles, AvoidVehicles, Cohere, Evade, Flee, FollowPath, Pursue, Seek, Separate, View, and Wander.
    Align, Cohere and Separate have an additional parameter: VisionAngle.
    New classes: SB_Grid, SB_Node and SB_Pathfinder, with new functions for pathfinding (based on a very fast variant of the A* algorithm)
    14 examples.

    I provide help only to my donators.

    The Accelerated Surface library is required to run the examples.
     

    Attached Files:

    Last edited: Jan 27, 2016
    Levit, paragkini, Erel and 4 others like this.
  2. bluedude

    bluedude Well-Known Member Licensed User

    Surface

    I think you forgot to tell we need another library to get this working :)
     
  3. Informatix

    Informatix Expert Licensed User

    Yes, I forgot to mention that you need my Accelerated Surface library (which is totally free) to run the examples. Thank you for reporting this mistake.
     
  4. Informatix

    Informatix Expert Licensed User

  5. Informatix

    Informatix Expert Licensed User

    Someone wanted to know how to draw an oriented bitmap instead of the circles used in the examples. So here's a modified demo.
     

    Attached Files:

    koaunglay likes this.
  6. walterf25

    walterf25 Well-Known Member Licensed User

    Will this work with libgdx library?
     
  7. Informatix

    Informatix Expert Licensed User

    Yes. It is a calculation library so it works with everything.
     
  8. Greg Conely

    Greg Conely Member Licensed User

    I am curious about making an application where you are not allowed to block a path from the vehicle to a set point (or two). All I see in the 1.1 version is step by step movement. Any way of telling if putting an obstacle down blocks the path for one or multiple vehicles?
     
  9. Informatix

    Informatix Expert Licensed User

    I'm not sure to understand your question. Please give me a detailed example of what you want to achieve. And what is a movement that's not done step by step?
     
  10. Greg Conely

    Greg Conely Member Licensed User

    I am building a game where enemies spawn from one or more points on the screen. They then try to get to your base on the other side of the screen. Players may lay down obstacles to steer them, but cannot completely block them from getting to your base. So I want to disallow the player from blocking the paths of the enemies completely. The enemies still move one step at a time.
     
  11. Informatix

    Informatix Expert Licensed User

    In the donationware version, you have a class to compute paths that allows to set a value for obstacles. 0 = no obstacle, 10 = solid obstacle, cannot be crossed. Any value in-between does not prevent moving through the obstacle, but higher is the value, less quick is the path.
     
  12. walterf25

    walterf25 Well-Known Member Licensed User

    Hi Informatix, i'm working on a sort of Air hockey game with libGDX, i'v yet to find a way to automate the cpu paddle, do you think your Steering behaviors library could be used for this purpose?

    Thanks,
    Walter
     
  13. Informatix

    Informatix Expert Licensed User

    Yes, absolutely. With the Arrive behavior.
     
  14. walterf25

    walterf25 Well-Known Member Licensed User

    Great, any chance you have an example with libgdx using Steering Behaviors library?

    :D

    Thanks,
    Walter
     
  15. Informatix

    Informatix Expert Licensed User

    This library does computations only. It does not produce any graphical output. So there's nothing to do specifically for libGDX. Draw your moving paddle at the computed position of the vehicle object. That's all.
     
  16. ilan

    ilan Expert Licensed User

    WOW!!! this is an amazing lib...
    thank you very much informatix!! :)
     
    Last edited: Jul 29, 2015
  17. ilan

    ilan Expert Licensed User

    hi

    if i would like to check if my Vehicle entered a path (area) what should i use for it?

    (crash if v touch path)

    crashontouchpath.jpg

    thank you,
    regards, ilan
     
  18. Informatix

    Informatix Expert Licensed User

    Box2D. Its collision detection is better and faster than the Steering Behaviors one.
     
    wonder likes this.
  19. ilan

    ilan Expert Licensed User

    thanx informatix, can i still use the steering behaviors?? i am making a libgdx game and moving my car with steering behaviors and now i need to add the road path and want my vehicle to report a crash if he collides with the road sides... my vehicle is moving perfect with the steering behaviors...

    can i also make it like this:

    Code:
    Dim ellipse As lgMathEllipse
    '...
    ellipse.Set(vpw*0.4,vpH*0.3,vpw*0.3,vpH*0.2)
    '...

      
    If v.Position.Xdip > ellipse.x AND v.Position.Xdip < ellipse.x + ellipse.width Then
         
    If v.Position.Ydip >  ellipse.y AND v.Position .Ydip < ellipse.y + ellipse.height Then
             
    Log("crash")
         
    End If
      
    End If
    i get the crash log if my vehicle enter the ellipse i just need to figure out how to make a custom path and check if vehicle EXIT this area..

    but i am :confused:
     
  20. Informatix

    Informatix Expert Licensed User

    SB handles only obstacles with a circular or rectangular shape so you will have to do complex calculations with other shapes. Don't forget to take into account the size of the vehicle for the detection and the risk of tunnel effect (that's why a stepped simulation with a little step is mandatory). You can use the functions of lgMathPolygon and lgMathIntersector to ease your work.

    Your collision test is only right for the AABB of the ellipse, not for the ellipse itself, and only if your vehicle is just a point. If this test suits your needs, use a rectangle instead. The ellipse is useless. Otherwise, use the Contains function of the lgMathEllipse function.
    Anyway, how do you detect that the car goes off the road with an ellipse ??? I don't understand the idea.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice