User Tag List

Results 1 to 10 of 10

Thread: RTS AI

  1. #1
    No Products Registered

    Join Date
    Feb 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RTS AI

    Are there any good ways to implement AI for an RTS type of game in MMF2? For example, right now I am spawning enemy units and having them walk towards the other side of the map. I want them to stop and shoot at other NPC units when they are in range. How would I define this range?

    I have thought of either using the distance formula, in relation to all units of the opposite faction, but I'm not sure of how to implement this idea.

    The other idea I have is to create an invisible circle around each unit and have the unit stop and shoot whenever some one collides with the circle. Either way, I have a feeling the algorithm and coniditons required to implement these might be a bit complicated, so i was wondering if anyone had any better ideas? Thanks a lot.

  2. #2
    No Products Registered

    Join Date
    Jun 2006
    Location
    Texas
    Posts
    1,002
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: RTS AI

    The distance formula is a good way to do this.

    You would have a variable spread in your units to ID them and a variable spread in the opponents. You need to iterate (loop through) all of your units and test them against all of the enemies to see if they are in range.

    The distance is of course the sqrt(pow(x2-x1)+pow(y2-y1)) check to see if that is less then or equal to the distance that you want to check for and if so then you have an enemy in range.

    So here is basically what you need to do:

    Always->Start loop X for number of units

    On Loop X, Start loop Y for number of enemy units.

    On Loop Y
    Alterable value A of "Units"=LoopIndex("X")
    Alterable value B of "Enemies"=LoopIndex("Y")
    Compare two general values: sqrt(pow(enemyX-unit+pow(enemyY-unitY))<rangetocheck then make unit fire at enemy.

  3. #3
    No Products Registered

    Join Date
    Feb 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: RTS AI

    So at the moment i have a qualifier on all units, two seperate qualifier for good side and bad side, and another two seperate qualifiers for good side units and bad side units? So thats a total of 3 qualifiers for each unit, which is manageable, but is there any way to rename qualifiers? So I dont have a bunch of qualifiers that are simply numbers that i need to keep track of?

  4. #4
    No Products Registered

    Join Date
    Jun 2006
    Location
    Texas
    Posts
    1,002
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: RTS AI

    Why do you need three qualifiers? You should just need one per unit.

    When I say good guys I mean Player 1 and when I say bad guys I mean the computer :P.


  5. #5
    No Products Registered

    Join Date
    Feb 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: RTS AI

    Right, but the player has his own allies too. The game I am trying to make will have two teams, but the player only controls one unit, and the fighting will be continuous between two AI controlled teams. So I will probably need two different types of loops, one for the enemies and the distance between all friendly units, including the player, and one for friendly units and the distance between all enemy units.

    I think you are right on the qualifiers, i just need one for "good unit", and one for "bad unit". I had three because i had one general "unit" qualifier, which defined things such as when HP < 0 = die, and boundary conditions. but maybe I dont need that after all.

    But yea, is there any way to rename them?

    Also, what is the exponent function? when I use pow, it keeps saying syntax error. Are there specific parameters for pow?

  6. #6
    No Products Registered

    Join Date
    Jun 2006
    Location
    Texas
    Posts
    1,002
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: RTS AI

    oops sorry, when I wrote that last night my brain was fried.

    It is really sqrt((x2-x1) pow 2+(y2-y1) pow 2) :P. .

  7. #7
    No Products Registered

    Join Date
    Jun 2006
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: RTS AI

    the problem with this is that the performance decreases exponentially with the number of units, since each new unit means that all units must increase the numbers of checks.

    If you have lots of units you might want to consider not doing this on EVERY loop. For example, you could loop through 10-20% of the units each loop, that way you get increased performance, with rather small impact on the game.

    Also, if you want to go really leet, you could divide the game into sectors, and then only make each unit loop through the enemy units that are in the same sector. Assiging of sectors would be done even more rarely than the range check, but i don't think such a thing would be needed.

  8. #8
    No Products Registered

    Join Date
    Feb 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: RTS AI

    I have a question about this algorithm and I dont really fully understand how it works.

    As I see it, Loop X basically iterates through all units.

    Loop Y iterates through all enemy units.

    On Loop Y, we set Alterable value A of "Units"=LoopIndex("X")
    Alterable value B of "Enemies"=LoopIndex("Y").

    First, why do I need to iterate through all units? Wont enemy units then be checking their distance against other enemy units?

    Also, what is the point of setting the Alterable value of units to loop index X and alterable value of enemies to loop index y? isn't it sufficient to simply check the distance between the current index of loop X against the current index of loop y?

    Sorry, I'm a nub sauce and a little confused.

  9. #9
    No Products Registered

    Join Date
    Feb 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: RTS AI

    Anyone have an explanation, or better implementation for this?

  10. #10
    No Products Registered

    Join Date
    Jun 2006
    Location
    Texas
    Posts
    1,002
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: RTS AI

    No it's not setting, it is comparing. You compare the Alterable A value to the loop index to select that particular object.

    It just checks every player unit against every enemy unit. It wouldn't check enemy units against each other.

Posting Permissions

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