The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 4 of 4

Thread: Game theory: Putting units in formation

  1. #1

    Afrostyle Game theory: Putting units in formation

    OK, I'm trying to make a game and something I want to implement is a simple way of putting units in formation.

    I thought about 2 ways of doing this:

    1) Putting them in quadrants and separating them evenly across them.




    Or 2) Making the distances between them same:



    I have it down in theory, but not really sure how I can do it coding wise.

    Any ideas?

    PS. Formation AROUND the leader, or red circle.

    EDIT: The more I think about it... I should just switch to tile-based...
    Last edited by zuperxtreme; May 24th, 2008 at 07:46 PM.

  2. #2
    You will be better off in a tilebased or gridbased environment. Grouping/formation is one of the game theories, that is often used with path-finding algorithms to give a good feel to the game. Formation is done with many different algorithms, and most programmers have their own approach to it. If you want to understand formation, then though it will seem very different, start with a carousel example...
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  3. #3
    Try messing around with this:

    var vel: Point = new Point(target.x - pos.x, target.y - pos.y);
    var velLength = vel.length();
    vel.Normalize(characterSpeed);
    if(velLength < 10){
    vel.x = 0;
    vel.y = 0;
    }

    and when updating the character increment it's position by the vel aka velocity.

    Do that for each of the units. You'll notice this is just vector math.

    Also if you want to study it. Just look at Boids. It's a group of algorithms for flocking behavior. If you study it long enough it should make sense. You'll end up with something like:
    http://www.assaultwars.com/flash/AS3Boids/AS3Boids.html

    It's a simple set of algorithms but it takes a lot of understanding to use them right.

    //here
    //also since people doing AI ask about steering it's crucial you understand the dot product of two vectors.
    and here's the algorithm basically once you understand dot product.
    Last edited by Sirisian; May 25th, 2008 at 02:37 AM.

  4. #4
    Quote Originally Posted by Sirisian View Post
    Try messing around with this:

    var vel: Point = new Point(target.x - pos.x, target.y - pos.y);
    var velLength = vel.length();
    vel.Normalize(characterSpeed);
    if(velLength < 10){
    vel.x = 0;
    vel.y = 0;
    }

    and when updating the character increment it's position by the vel aka velocity.

    Do that for each of the units. You'll notice this is just vector math.

    Also if you want to study it. Just look at Boids. It's a group of algorithms for flocking behavior. If you study it long enough it should make sense. You'll end up with something like:
    http://www.assaultwars.com/flash/AS3Boids/AS3Boids.html

    It's a simple set of algorithms but it takes a lot of understanding to use them right.

    //here
    //also since people doing AI ask about steering it's crucial you understand the dot product of two vectors.
    and here's the algorithm basically once you understand dot product.
    Thanks a ton. It looks like I have more work ahead of me than expected.

    Cheers!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012