RTS Resource Collector AI

0 favourites
From the Asset Store
Mine those precious space resources & start trading
  • Hi guys, I am creating a RTS game and now I need to create a "AI" for the resource collector (like in Starcraft, Age of Empires and others) where the collector, after selected, if you click in a resource it go there, collect then go back to base and so on until it deplet the resource.

    Here is what i was able to make:


    Sorry if there is a english error, not my mother language.

  • Your example looks to be functioning very well to me. What is it that you need help with, exactly?

  • I need it to work with multiple "miners", Mines, and bases. The miners need to find the nearest base, find the nearest "mine" (with a max of miners alredy in it of X, if miners in that mine is X, then find another, the same way the workers in Starcraft 2 do). If i put 2 mines and 2 miners, the 2 miner will go crazy. Also, i cant make it that i can select it, chose a mine and it will go there (tried applying this in the game that i have that has unit selection). Understand what i mean?

  • This is what i want to do:


  • Come on guys, no one knows how to do it?

  • yeah patience young jedi..all things will be 'revealed'..in good time...I built a similar ai for a space harvesting game...I see if I can dig up the ai script...might take a day or two.....Sounds like you are nearly there anyway...One way to avoid the "crazies' in Miner 2 is to put a Wait script sequence...so..In Pseudo code

    if -> Mine = busy(occupied)

    then Miner 2 wait in holding pattern..

    if mine = free(unoccupied)

    then Miner 2 goto Mine and get some!!

    This is how Warcraft rts's do it..

    or the other way i have used before is to have stations...

    points around the mine...which could be represented as image points offset from the image..

    when the Miner goes to the mine

    run a check for open image points..

    with something like

    using the same idea as above

    -> Miner goto object"MINE" when it arrives..set it to image point 1

    then when the mine is occupied and a second miner comes along

    if Mine is busy(Occupied)..

    -> Miner2 set position to Image point 2 or 3 or 4 or how ever many miner docking points you wish..:D

    you sound like you just need to plan it all out a little more on paper first..

    its always a good idea to map out what has to happen with every process in your game

    RTS games are all about Processes..

    first this

    then that

    so build some visual tree diagrams(flow charts) to help you unsderstand what process you need to make it work..

    its all about the planning process..


    take your time..

    get it right:D

    ill try to dig up that rts mining script i had ..it was neat...very simple..less than 20 events..

  • Yes, it helped, a little, but the main problem i have is that the second miner does not collect all 15 resources it should, and after that is just goes crazy...

    I tried adding a sprite for overlap(to see when it was collecting, since just putting it to stop while "isCollectin=true" stoped the game (crashed, i think), and, worked, somewhat, but the second miner pass the mine, THEN stop, and both start ignoring walls and dont find the path to the base.

  • Here is an old example of units collecting stuff I did a while back:

    Harvester example

  • vee41

    I see what you did, tried to do it, but doesnt work with pathfinding.

    here is updated:


  • vee41

    I see what you did, tried to do it, but doesnt work with pathfinding.

    here is updated:


    Few simple fixes, you were quite close :)

    RTS harvester example

  • vee41

    Thanks, it worked. But I want to make it every GatherSpeed -> add 1 to goods.

    I tried, it works, somewhat. After de first one reach his goods capacity, the 2 one stops and when the first one get back, it also stop.

    Here is the updated:

    dropbox.com/s/roqhfuvjapoylye/Miner.capx (same link :))

  • Updated the link I posted before with that functionality.

  • vee41

    Thanks, a lot.

    Now i will try to add the select unit functionality (alredy have it, but need to implement the harvesters in the game and see if it works. If I have any problem, i will post. Thanks again.

  • vee41

    Hey vee, I am with a problem. I am trying to make the collector go to a selected Oil pool, because if i can do this, i will be able to make it go to Oil or Food (the other resource). I was able to make it go, but, once it drop the resource, it goes crazy, he simple stay in the same place, "dancing".

    Also, if you guys have some tips, leave them there.

    Here is the link to the "game" version:


  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Anybody?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)