Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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