• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] Move unit towards a Region

Status
Not open for further replies.
Level 28
Joined
Jan 26, 2007
Messages
4,789
The event for the trigger will be "Unit - a unit enters Region 1" (obviously).
Conditions are yours to choose (if it can be any unit at all, don't add any conditions).

Now you will need 3 variables: tempLoc1, tempLoc2 and tempLoc3 (all are point-variables). They only serve to remove the leaks (which slow down the game, that's a bad thing).
Note that these are usually the only 3 point-variables you'll ever need (some exceptions, but I won't go into that any further).

tempLoc1 will be the center of Region 1
tempLoc2 will be the position of the units in Region 2
tempLoc3 will be the the position of those units, but then moved 100 units towards the center of Region 1 (tempLoc1).

Okay, tempLoc1 can be set at the start of the trigger - no problem.
Then we will need a unit group. Thing is: unit groups also leak (slow down the game), thus we need to remove that. I use a custom script for that ("set bj_wantDestroyGroup = true").
In the unit group, we pick all units in Region 2 and set tempLoc2 to the location of the picked unit.
Then we set tempLoc3 to "point with polar offset". The point is tempLoc2, the offset is 100 units, the angle is (angle from tempLoc2 to tempLoc1).
Then you instantly move the unit to tempLoc3 and you're almost done.
All that's left now is to remove the location leaks, this is done with another custom script ("call RemoveLocation( udg_variableName )".

The trigger will look like this:
  • Move Units
    • Events
      • Unit - A unit enters Region 1 <gen>
    • Conditions
    • Actions
      • Set tempLoc1 = (Center of Region 1 <gen>)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in Region 2 <gen>) and do (Actions)
        • Loop - Actions
          • Set tempLoc2 = (Position of (Picked unit))
          • Set tempLoc3 = ((Center of (Playable map area)) offset by 100.00 towards (Angle from tempLoc2 to tempLoc1) degrees)
          • Unit - Move (Picked unit) instantly to tempLoc3
          • Custom script: call RemoveLocation( udg_tempLoc2 )
          • Custom script: call RemoveLocation( udg_tempLoc3 )
      • Custom script: call RemoveLocation( udg_tempLoc1 )
Most of this is leak-fixing, but it's really important.
If you don't know already, you should learn how to clean those.
 
Status
Not open for further replies.
Top