Multiple Path Brain-fart

0 favourites
  • 3 posts
From the Asset Store
Complete casual and addictive game, easy to modify and market
  • Hello there fellow beans. I've been up all night trying to find a way to solve this issue i'm having. I cant even think anymore so forgive me if its a simple one.

    Turret A is on a set path (in a straight line) to Turret B when it is spawned. I have another Turret, lets call this guy Turret E because its an awkward bastard.

    Turret E is located outside Turret A's range when 'A' moves along its path.

    What i need to do is get A to target E and then move within firing range (I cannot increase Turret A's firing range). After the illusive E is deceased, i then need 'A' to carry on his merry way to Turret B.

    Basically, i need a 'detect and move to' range, that is separate from the turrets actual fire range.

    Thanks in advance for any replies, peace.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can do that with the distance function

    //Check for nearby enemies
    Turret_A.In_combat = False                                             (Only Turret_A's that are not in combat)
    For each Turret_A
        Distance(Turret_A.X, Turret_A.Y, Turret_E.X, Turret_E.Y) <= 500
                   Turret_A.Go_to_Turret_B = False                     (Variable to make sure that turret don't go towards B)
                   Turret_A.Attack_Turret_E = Turret_E.UID       (Store the UID of Turret_E that A is attacking) 
                   Turret_A find path to (Turret_E.X, Turret_E.Y)
    
    (If Turrent_E is stationary you don't have to keep finding a path to it, so you could add a variable to make sure of that.)
    
    //Move Turret_A
    On path found Turret_A          
                    Turret_A.Move along path
    
    //Turret A is attacking Turret_E
    Turret_A.Attack_Turret_E != -1                                             (Only pick A's that have a target)
    For each Turret_A
           Turret_E.UID = Turret_A.Attack_Turret_E                     (Pick correct Turret_E)
           Distance(Turret_A.X, Turret_A.Y, Turret_E.X, Turret_E.Y) <= Firing_range
           Turret_A.stop
           Turret_A.In_combat = true                                      (Makes sure that Turret_A wont keep looking for path to E or B) 
    
    //When Turret A destroys E
    Turret_E.Destroyed
          Turret_A.Attack_Turret_E  = Turret_E.UID              (Select all Turret_A that have the destroyed E as target)
          For each Turret_A       
               Set Turret_A.Attack_Turret_E = -1                       (Reset so there are no target selected)
               Turret_A.In_combat = False
          
    //Return to going to B
    Turret_A.In_Combat = False
    Turret_A.Go_to_B = False
    For each Turret_A
           Turret_A Find path to (Turret_B.X, Turret_B.Y)
           Turret_A.Go_to_B = True                                         (Make sure that it doesn't keep looking for a path) 
    [/code:t0bgh4jm]
    
    Minor adjustments might be needed, but I think it would work.
  • Thanks for the help, got it sorted now. Kinda very new at this and from staring at your reply for a good few hours scratching my head, ive discovered the power of using 1's and 0's to trip the fuck out of a computer and make it do crazy things that only Neo himself would dream of. I am now the Matrix.

    110111

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