Triggered Movement

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
How do you make a trigger which moves a unit smoothly toward a target point? Like in Sliding triggers or skills like Faceless Void's Vacuum which sucks all units toward a target point with a sort of sliding movement, instead of moving it there instantly regardless of distance.
 

linamus

I r bak!
Reaction score
57
You have in mind, like moving the target as it was sorceress-type unit? Floating to the point without producing movement animations?
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
No, I mean like you drift to a certain point or towards a certain direction, but it may not affect your current orders.
 

linamus

I r bak!
Reaction score
57
So, like an invisible rope would drag you to the point while you can still be channeling some spells?
 

tommerbob

Minecraft. :D
Reaction score
110
The easy way is to periodically move a unit to a point offset by X amount towards an angle (such as the facing angle of the unit), every ~.03 seconds.

If you don't want to interrupt the unit's current orders, however, you have to use the Jass functions for setting a unit's coordinates (X,Y).
 

Ayanami

칼리
Reaction score
288
Well, do you know how to do a periodic sliding trigger? Basically, you use SetUnitX() and SetUnitY().
 

Ayanami

칼리
Reaction score
288
Well, first you need to understand that all Sliding triggers make use of the instant move actions, which is Unit - Move unit (instantly). However, a sliding trigger moves the unit over a period of time, with a small distance moved per period.

So let's say you want a unit to travel 1000 distance. If you used Unit - Move unit (instantly) straight away to the end-point, it would basically look like a blink.

For a sliding effect, you make use of a periodic trigger.

Trigger:
  • Slide
    • Events
      • Time - Every 0.03 seconds of game time


You'll need to use a period of 0.04 or less to produce a smooth sliding effect. So now, you need to determine how fast you want the unit to slide. Set a variable Speed, which determines the distance traveled per second.

Trigger:
  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Speed = 1000.0


Speed is set to 1000. This would mean that it would take 1 second for the unit to slide the total distance (1000). From this, you can make your sliding trigger.

Trigger:
  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Speed = 1000.0
      • Set Distance = 1000.0


Trigger:
  • Slide
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
      • Distance is Greater than 0.00
    • Actions
      • Set SlideUnit = <some unit>
      • Set TempPoint = (Position of SlideUnit)
      • Set TempOffset = (TempPoint offset by (Speed x 0.03) towards SomeAngle)
      • Unit - Move SlideUnit instantly to TempOffset
      • Set Distance = (Distance - (Speed x 0.03))
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Custom script: call RemoveLocation(udg_TempOffset)


Basically, you're moving the unit 30 distance towards the SomeAngle every 0.03 seconds, which would amount up to 1000 distance per second.

Now, by Sliding a unit via the method shown above, it would cause the unit to be "paused", meaning it won't be able to carry out any given orders. This is where you need to use [ljass]SetUnitX()[/ljass] and [ljass]SetUnitY()[/ljass]. Basically, you replace the Unit - Move unit (instantly) with the 2 actions. Example:

Trigger:
  • Slide
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
      • Distance is Greater than 0.00
    • Actions
      • Set SlideUnit = <some unit>
      • Set TempPoint = (Position of SlideUnit)
      • Set TempOffset = (TempPoint offset by (Speed x 0.03) towards SomeAngle)
      • Set RealX = (X of TempOffset)
      • Set RealY = (Y of TempOffset)
      • Custom script: call SetUnitX(udg_RealX)
      • Custom script: call SetUnitY(udg_RealY)
      • Set Distance = (Distance - (Speed x 0.03))
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Custom script: call RemoveLocation(udg_TempOffset)


To make it MUI, you'd need a bit more work. But the sliding concept is the same.
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Would this work on units in a unit group? Then I could just use different variables for different triggers.
 

Ayanami

칼리
Reaction score
288
Would this work on units in a unit group? Then I could just use different variables for different triggers.

Yes, it would work in a unit group. Just that you'd need a method to store different values for different units. You could use arrays, or hashtable (which IMO is the easier method).
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
What goes in the brackets of SetUnitX() and SetUnitY()?
(Sorry for all the questions)
 

Ayanami

칼리
Reaction score
288
What goes in the brackets of SetUnitX() and SetUnitY()?
(Sorry for all the questions)

Ah, forgot to say and made an error on the above post.

[ljass]SetUnitX(Unit, Coordinate)[/ljass]

Unit is basically the unit you want to move. Coordinate is the coordinate of the location. This can be obtained by using a real variable. You can set a real variable to "X of Point" and "Y of Point".
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Trigger:
  • Surge Movement
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in FlameSurgeUnits and do (Actions)
        • Loop - Actions
          • Set TempPoint = (Position of (Picked unit))
          • Set TempPoint2 = (TempPoint offset by 25.00 towards (Facing of (Picked unit)) degrees)
          • Unit - Move (Picked unit) instantly to TempPoint2
          • Unit - Create 1 Dummy Unit for (Owner of (Picked unit)) at TempPoint facing Default building facing degrees
          • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
          • Hashtable - Save ((Load 1 of (Key (Picked unit)) from SurgeUnitDistanceHash) - 25.00) as 1 of (Key (Picked unit)) in SurgeUnitDistanceHash
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load 1 of (Key (Picked unit)) from SurgeUnitDistanceHash) Less than or equal to 0.00
            • Then - Actions
              • Unit Group - Remove (Picked unit) from FlameSurgeUnits
              • Unit - Make (Picked unit) Vulnerable
            • Else - Actions
          • Set TempUnit = (Picked unit)
          • Set TempHandle = (Picked unit)
          • Set TempPoint = (Position of (Picked unit))
          • Unit Group - Pick every unit in (Units within 200.00 of TempPoint) and do (Actions)
            • Loop - Actions
              • Set TempUnit2 = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (TempUnit2 is alive) Equal to True
                  • (TempUnit2 is A structure) Equal to False
                  • (TempUnit2 belongs to an enemy of (Owner of TempUnit)) Equal to True
                  • (TempUnit2 is in (Load 1 of (Key TempHandle) in SurgeUnitGroupHash)) Equal to False
                • Then - Actions
                  • Unit - Cause TempUnit to damage TempUnit2, dealing (50.00 x ((Real((Level of Flame Surge for TempUnit))) + 1.00)) damage of attack type Spells and damage type Fire
                  • Unit Group - Add TempUnit2 to (Load 1 of (Key TempHandle) in SurgeUnitGroupHash)
                • Else - Actions
          • Custom script: call RemoveLocation(udg_TempPoint)
          • Custom script: call RemoveLocation(udg_TempPoint2)

Why doesn't the above trigger work? The movement is fine, but the units are damaged every time the trigger runs - not just once. Is it something to do with one Pick Every Unit action within another one?
 

Ayanami

칼리
Reaction score
288
You should make sure that the units are actually being added to the unit group. That could be the problem. Your unit group leaks as well. Sore the "Pick every unit" part into a group and destroy it. And you leak a location in that line too. Also, isn't creating 1 dummy unit per 0.03 going to make things EXTREMELY laggy? o.o
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Actually the movement is fine. But the units aren't added to the unit group, so is there a way to fix it?
 

tommerbob

Minecraft. :D
Reaction score
110
What are your dummy units for? And what exactly are you trying to do besides simply sliding units around?
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
The dummy units simply create an exploding effect. I used dummy units because the original effect didn't look as good. And the trigger is supposed to cause damage to units within an area, then add them into a unit group so that they only get damaged once.
 

hgkjfhfdsj

Active Member
Reaction score
55
it might be b/c ur hashtable SurgeUnitGroupHash doesnt have an initialized group saved to it.
put something like this in the spell effect event trigger.
Code:
Custom Script: set LoadGroupHandle(udg_SurgeUnitGroupHash, udg_TempHandle, 1) = CreateGroup()
then later destroying it when movement is over.

Also it seems like youre using 1 hashtable for each 'variable' ie Distance, GroupHash. you could try using 1 hashtable and use it as a 2d array.

eg
Save (Dist - 25) as 1 of Key (TempHandle) in (Hashtable)
Save (Damaged) as 2 of Key (TempHandle) in (Hashtable)
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Well, actually I solved the problem around 1 a.m. last night. Here's the triggers:
Trigger:
  • Surge Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Flame Surge
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • Set TempPoint2 = (Target point of ability being cast)
      • Set SurgeUnitNumber = (SurgeUnitNumber + 1)
      • Hashtable - Save False as SurgeUnitNumber of 4 in FlameSurgeHashtable
      • Hashtable - Save Handle Of(Triggering unit) as SurgeUnitNumber of 1 in FlameSurgeHashtable
      • Hashtable - Save Handle Of(Random 0 units from (Units in (Playable map area))) as SurgeUnitNumber of 3 in FlameSurgeHashtable
      • Hashtable - Save (Distance between TempPoint and TempPoint2) as SurgeUnitNumber of 2 in FlameSurgeHashtable
      • Hashtable - Save (Angle from TempPoint to TempPoint2) as SurgeUnitNumber of 5 in FlameSurgeHashtable
      • Unit - Make (Triggering unit) Invulnerable
      • Unit Group - Add (Triggering unit) to SurgingUnits
      • -------- SurgeUnitNumber tracks the NUMBER OF UNITS IN SurgeUnits. --------
      • -------- All data related to the unit casting Flame Surge is saved within the hashtable using the current SurgeUnitNumber. --------
      • -------- [SurgeUnitNumber of 1 in FlameSurgeHashtable] is the UNIT casting Flame Surge. --------
      • -------- [SurgeUnitNumber of 2 in FlameSurgeHashtable] is the DISTANCE between the unit casting Flame Surge and its targeted position. --------
      • -------- [SurgeUnitNumber of 3 in FlameSurgeHashtable] is the UNIT GROUP which contains all units that have been struck by this unit in the current Flame Surge. --------
      • -------- [SurgeUnitNumber of 4 in FlameSurgeHashtable] is the BOOLEAN which tells whether the current integer slots have already been used. --------
      • -------- [SurgeUnitNumber of 5 in FlameSurgeHashtable] is the ANGLE between the casting unit and the target point. --------
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Custom script: call RemoveLocation(udg_TempPoint2)

Trigger:
  • Surge Movement
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to SurgeUnitNumber, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load (Integer A) of 1 in FlameSurgeHashtable) Not equal to No unit
              • (Load (Integer A) of 4 from FlameSurgeHashtable) Equal to False
            • Then - Actions
              • Set TempUnit = (Load (Integer A) of 1 in FlameSurgeHashtable)
              • Set TempPoint = (Position of TempUnit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Facing of TempUnit) Not equal to (Load (Integer A) of 5 from FlameSurgeHashtable)
                • Then - Actions
                  • Unit - Move TempUnit instantly to TempPoint, facing (Load (Integer A) of 5 from FlameSurgeHashtable) degrees
                • Else - Actions
              • Set TempPoint2 = (TempPoint offset by 25.00 towards (Facing of TempUnit) degrees)
              • Unit - Move TempUnit instantly to TempPoint2
              • Hashtable - Save ((Load (Integer A) of 2 from FlameSurgeHashtable) - 25.00) as (Integer A) of 2 in FlameSurgeHashtable
              • Unit - Create 1 Dummy Unit for Neutral Passive at TempPoint2 facing Default building facing degrees
              • Unit - Add a 0.01 second Generic expiration timer to (Last created unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load (Integer A) of 2 from FlameSurgeHashtable) Less than or equal to 25.00
                • Then - Actions
                  • Set TempPoint = (Position of TempUnit)
                  • Set TempPoint2 = (TempPoint offset by (Load (Integer A) of 2 from (Last created hashtable)) towards (Facing of TempUnit) degrees)
                  • Unit - Move TempUnit instantly to TempPoint2
                  • Hashtable - Save 0.00 as (Integer A) of 2 in FlameSurgeHashtable
                  • Hashtable - Save Handle OfNo unit as (Integer A) of 1 in FlameSurgeHashtable
                  • Hashtable - Save True as (Integer A) of 4 in FlameSurgeHashtable
                  • Unit Group - Remove TempUnit from SurgingUnits
                  • Unit - Make TempUnit Vulnerable
                • Else - Actions
              • Set TempUnitGroup = (Units within 200.00 of TempPoint)
              • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
                • Loop - Actions
                  • Set TempUnit2 = (Picked unit)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (TempUnit2 is alive) Equal to True
                      • (TempUnit2 is A structure) Equal to False
                      • (TempUnit2 belongs to an enemy of (Owner of TempUnit)) Equal to True
                      • (TempUnit2 is in (Load (Integer A) of 3 in FlameSurgeHashtable)) Equal to False
                    • Then - Actions
                      • Unit - Cause TempUnit to damage TempUnit2, dealing (50.00 x ((Real((Level of Flame Surge for TempUnit))) + 1.00)) damage of attack type Spells and damage type Fire
                      • Unit Group - Add TempUnit2 to (Load (Integer A) of 3 in FlameSurgeHashtable)
                    • Else - Actions
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load (Integer A) of 1 in FlameSurgeHashtable) Equal to No unit
                  • (Load (Integer A) of 4 from FlameSurgeHashtable) Equal to True
                • Then - Actions
                  • Hashtable - Clear all child hashtables of child (Integer A) in FlameSurgeHashtable
                • Else - Actions
          • Custom script: call RemoveLocation(udg_TempPoint)
          • Custom script: call RemoveLocation(udg_TempPoint2)
          • Custom script: call DestroyGroup(udg_TempUnitGroup)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top