• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Problem with Attack Moving wave creeps

Status
Not open for further replies.
Level 2
Joined
May 20, 2015
Messages
25
Hello everyone! I am making a wave system for my survival map and recently I implemented a trigger that when a unit spawns, it checks the closest hero to it and attack moves to its location. At least that's what I want it to do, however since I'm new to all these triggers and whatnot somehow I implemented the trigger wrong and it doesn't do what I want it to.

When a creep spawns, it does check the closest hero (someone helped me with this part, many thanks to him). After checking the closest hero the creep attack moves to its location and so far so good, however if the hero moves its position when the attack move command is issued to the creep or if the creep cant find a target at all in the nearby area it simply walks back to the spawn area and attack moves the hero again.

This results in a constant loop of the creep getting ordered to attack move, doesn't find anything so it moves back and then attack moves again until it gets near the hero, in which case it finally decides to attack it.

Can someone tell me where the problem is and how to solve it please? Here is the trigger:

  • Creep Attack Move
    • Events
      • Unit - A unit enters Creep Spawn <gen>
    • Conditions
      • (Owner of (Entering unit)) Equal to Player 11 (Dark Green)
    • Actions
      • Set TempPoint = (Position of (Last created unit))
      • Set TempHeroGroup = (Units in (Entire map) matching (((Matching unit) is A Hero) Equal to True))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (TempHeroGroup is empty) Equal to False
        • Then - Actions
          • Set ClosestHeroUnit = (Random unit from TempHeroGroup)
          • Set TempPoint2 = (Position of ClosestHeroUnit)
          • Set MinDistance = (Distance between TempPoint and TempPoint2)
          • Custom script: call RemoveLocation(udg_TempPoint2)
          • Unit Group - Pick every unit in TempHeroGroup and do (Actions)
            • Loop - Actions
              • Set TempPoint2 = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between TempPoint and TempPoint2) Less than MinDistance
                • Then - Actions
                  • Set MinDistance = (Distance between TempPoint and TempPoint2)
                  • Set ClosestHeroPoint = (Position of (Picked unit))
                • Else - Actions
              • Custom script: call RemoveLocation(udg_TempPoint2)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Custom script: call DestroyGroup(udg_TempHeroGroup)
      • Unit - Order (Entering unit) to Attack-Move To ClosestHeroPoint
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Well your trigger is not wrong. it does everything it should do. When it enters the region, it will attack move to the point, but if the hero moves away, the unit will still attack move to the same point. If it finishes it's order (reached that point and no enemy nearby) the unit will return to it's starting location. This is normal warcraft 3 AI behaviour I think.
You will probably have more success, if the unit checks constantly for the closest hero nearby and attack move to that position. This will ensure, that the unit always attack moves towards to the currently closest hero. You can implement this with a periodic trigger, though you have to be careful to avoid fps drops, because you will perform this for multiple units. You should also keep in mind, that re-ordering an order will cancel the current orders, so if a unit is currently attacking and you order it to attack-move, the attack will be cancel, so this should be avoided.
 
Level 2
Joined
May 20, 2015
Messages
25
Ahh okay. So basically I want to change the event to a periodical one so lets say every X seconds of game time? If I understand you correctly that should solve it, correct?
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Yeah, periodic timer and unit group to pick every unit of player 11. It's very inefficient though to use periodic timer + unit group in unit group, so you will have to see if it lags. There are better more difficult solutions, that might be necessary, if this method causes lags.
 
Level 2
Joined
May 20, 2015
Messages
25
Alright, I'll test it out in a bit and see how much it affects performance. Good thing I have a really s**t laptop so I can notice if it lags sooner. On a side note, I am planning of having about 50-70 creeps on the map at the same time. Lets hope it wont lag.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
you will have c creeps and h heroes.
The first unit group loops through all creeps
and the second unit group loops through all heroes to find the closest. This will be done for every creep.
In total you will have a complexity of c*h, so depending on the amount of heroes, this can be quite performance heavy.
I don't have the numbers in my head when it starts to be problematic, you will have to test.
 
Level 2
Joined
May 20, 2015
Messages
25
...I'm confused. I started making my first ever map about a week ago so I have no clue how to loop through the creeps and heroes to find find the closest for eeeevery creep. Do I keep the trigger and add stuff to it or keep some parts and add stuff or... I'm trying to wrap my head around this but the thing that you said sounds like what my trigger does but at the same time it doesn't sound like it... Aggghhh!!!
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
By the way the trigger to determine the position of the closest hero leaks.
Set ClosestHeroPoint = (Position of (Picked unit)) will be executed multiple times without removing it at any point.
Check the test map out. This is a very basic approach and it's still bad, because it cancels attack every 2 seconds.

I got a bit of lag with 10 heroes and 60 enemies (barely noticeable, but it's there).


Advanced version (AttackMoveSplit) using this:
GUI Unit Indexer 1.2.0.2
I tested the advanced version with 170 enemies and 50 heroes.
 

Attachments

  • AttackMove2.w3x
    17.5 KB · Views: 110
  • AttackMoveSplit.w3x
    24.7 KB · Views: 106
Last edited:
Level 2
Joined
May 20, 2015
Messages
25
Awesome! Thank you very much for the help! I'll try and figure something out for the attack cancel, it shouldn't be that hard (lets hope). Implementing this has been one of the hardest things so far that I came across to be honest but thank god I have Hive where people can help me out! ^^ Thanks again and +rep to you.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
it shouldn't be that hard (lets hope)
I think it won't be easy. I am not sure how this can be done the best way. You can't check for orders, because when a unit is on attack-move its order is always attack. Maybe do not order units that have been attacking for the last 2 seconds or so. That would be very hard for you though.
 
Level 2
Joined
May 20, 2015
Messages
25
The problem with that though would be that the units wouldn't be able to follow the heroes I believe since you need to constantly give them an attack move order for them to go towards the hero at all times.
I just had a thought in my mind.
How do other survival maps manage to keep track of your location and order creeps to attack you without the creeps behaving awkwardly? Because it must be doable since every map I played that had this type of element in it didn't have this issue. Maybe I'm just missing something and there is something else involved that allows the creeps to be so precise. Too bad most maps are protected so you can't see how they done it.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
You could do something like this: if distance is smaller than 500 for example you don't give them attack orders. They are close enough, that their current attack move order will make them attack anyway, so no new orders are necessary. This does not work, if the unit attacks units while it's too far away from the position it's moving to, but that's only possible, if there are other units than heroes it attacks.
I don't know how they do it, I have not played many survival maps. Probably they have a simpler solution. Maybe they even cancel attacks sometimes and you never realized it.
 
Level 2
Joined
May 20, 2015
Messages
25
The only thing besides Heroes in my map would be a few buildings and some summoned units so I don't know how much that would affect the creeps. Well, I guess I'll try it out, if it doesn't work I'll try something else. To be honest if everything fails I cooooouuuuld take the waves away, but then I would need to seriously re-design the map since I want that to be a major part of the game. I have some ideas if this will be the case but I really want to keep the design as is.
Regarding attack cancels, I have never seen creeps behave like they do currently in my map. They somehow always know where the Hero is, just as if they are being issued an "Attack" command rather than "Attack Move", but that wouldn't explain why in maps where there are other units and/or buildings they behave like its an Attack Move command.
 
Status
Not open for further replies.
Top