Need help with Simple A.I. for RTS like game.

0 favourites
  • 2 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hello Im trying to make 2 armies of units fight each other. So I have simple "Unit" that is like a Spearman. "Unit" is a Family I made in C3 in the layout there is 2 armies of Spearmen each in a line. On startup the "Units" move towards the opposite side and should detect any Unit that is on the other Team within range then call function "Attack" to the nearest enemy. The Attack would be a simple spawning of a Missile\attack sprite on the attacking Unit like a bullet.

    I have tested this having Team 1 Units, Team 2 Units as family's and objects and it works. But If I use this method I have to have multiple Units for each team. There must be a way to do it by Comparing Variable Unit.Team not= to other unit.Team variable but I can not figure it out. ]

    What is the best method of doing this?? Ill post a example If you dont understand what im asking.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So let's say "Spearman" and "Archer" are sprites, combined into a family "Unit". On this family you have an instance variable "team". You need to also create a copy of the family, let's call it "UnitAttacker".

    Then you can do something like this:

    variable currentTeam=1
    
    Every 1 second
    Unit team=currentTeam
    For each Unit
    	-> Function call "FindTarget" (Unit.UID)
    
    
    On Function "FindTarget"
     UnitAttacker pick by unique ID Function.param(0)
    	Unit team not equal currentTeam
    	UnitAttacker has Line of Sight to Unit
    	Unit pick nearest to UnitAttacker.x, UnitAttacker.y
    	 -> Function call "Attack" (parameters: UnitAttacker.UID, Unit.UID)
    
    

    In the "Attack" function you can pick both the attacker and the opponent instances by their UIDs.

    .

    So you can use two families to pick two separate units in the same event. However, only one family can have "team" instance variable, that's why I'm using "FindTarget" function here - to pick a member of UnitAttacker by UID.

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