Search Unity

2D Pathfinding like mushroom wars

Discussion in '2D' started by godlaugh, Aug 8, 2014.

  1. godlaugh

    godlaugh

    Joined:
    Mar 21, 2013
    Posts:
    1
    hi, Is there anyone know how to implement the pathfinding for several row army like mushroom wars

    * walk row by row , there is 8 soldiers every row
    * row soldier split when hit building obstacle, maybe split result is 4-4,or 3-5 or 2-6 or 1-7
    * shrink team formation width when path is narrow
    * every row soldiers arrive the target building at the same time

    mushroom wars video ref:
     

    Attached Files:

  2. Punchbag

    Punchbag

    Joined:
    Oct 30, 2012
    Posts:
    48
    This is actually a really clever 'illusion' generated by the combination of a couple of algorithms.

    • You've got typical NavMesh or Grid-Based A* pathfinding getting you the route for a squad (not an individual).
    • Squads are just groups of units that are close enough together and have the same goal.
    • They get spread out like that by Boid's Flocking Algorithm. Its a very simple concept created in the 80s that gives weights to staying together, staying apart and moving in the same direction so that your units look like they're intelligently moving together instead of piling on top of on another in a single line.
    So my approach would be for each individual unit to figure out who, nearby, has the same target as he does. Put them all in the same squad collection. Give that squad collection a single path to follow from centre of squad to destination location. Each unit then follows that path, using Boid's algorithm to stay apart from each other, but close enough, and moving in the same direction. If they get separated too far, re-squad them, re-path them, etc.

    You'll want to build it into the Boid weights that the closer they are to final destination, the more weight that direction has, so that they all pile in like they do at the end of their routes in the video.

    Excellent article on Boids: http://www.red3d.com/cwr/boids/

    Good luck!

    EDIT
    Rewatching the video, looks like they've added an additional weight for units to try and stay in row formation. Once you've got the pathing and flocking in, you'll probably want to incorporate that too.