Search Unity

How can I get units to stop packing on the same point.

Discussion in 'Scripting' started by ttdburnout, Apr 23, 2014.

  1. ttdburnout

    ttdburnout

    Joined:
    Apr 23, 2014
    Posts:
    9
    Hi,

    I'm developing an RTS game with A*PathFinding Project and I have a problem, when I right click to give a new Target to my units they pack together at the same point, And I would like them to organize as a squadron.

    Do you have any clue on how I could get this ?
     
  2. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    Instead of doing a path for each unit, do a single path for the selected units, then change the final waypoint of the path to be offset in the formation that you want for each unit. Then move the units using each of the modified paths
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    Doesn't help though if all the units are coming from different locations.

    //done with a leader perspective, this is good for "formation"
    Everyone calculate their path.
    Everyone register that they're heading to that path.
    Calculate the formation that should occur once everyone is there.
    Head towards goal.
    When near goal, but not at goal, check who is there. Calculate which is the best position in that formation for that unit (closest to them, but also packed in closest).
    Go to that point instead.

    //a none formation move
    Calculate path.
    Head towards goal.
    When get there, do a check to see who is already their (sphere cast?), get as close to the goal with out standing on anyone.

    //hybrid with previous suggestion
    Perform formation algorithm, but for a closer point... a semi-goal.
    Get into formation there.
    Then calculate one path to final goal.
    Everyone heads towards final goal.



    You could even get creative where the path of someone else impacts the choice of another. Lets say you're on a grid system, so every node change is of equal distance. When calculating the path, you know which step you're on, so if you have the defined path of previous players, you know where they're standing at specific times. You can then put weights on the spots they are standing at the point in time. When doing this, this means that when you go to calc the 10th units goal, the goal will be occupied (though not actually occupied, it'll just be weighted as such because you're considering the previous 9 paths), so when calculating... it'll just choose a goal point as close to the goal as it can get.



    Really, there's all sorts of ways to deal with this problem. Design one that behaves the way you want it to.
     
    Last edited: Apr 23, 2014
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    What we did was add an Occupied flag to each point in our navigation graph. Paths are calculated to the point the user clicked but upon arrival each unit finds and Occupies the closest point on the graph that is empty. The result is that each unit will move to the same spot but then "fan out" around that spot as graph points fill up.
     
  5. ttdburnout

    ttdburnout

    Joined:
    Apr 23, 2014
    Posts:
    9
    Ok, Do you think it is possible to make an RTS with advanced fantasy ai 2.0 ?