• 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.

[Spell] Help with understanding spirals

Status
Not open for further replies.
Level 3
Joined
Sep 9, 2009
Messages
658
So I'm reading Daelin's tutorial about spirals and I have a few questions.

  • For each (Integer A) from 1 to 20, do (Actions)
    • Loop - Actions
      • For each (Integer B) from 1 to 7, do (Actions)
        • Loop - Actions
          • Unit - Create 1 Missile for Player 1 (Red) at (CENTER offset by (100.00 + (8.00 x (Real((Integer A))))) towards (((360.00 / 7.00) x (Real((Integer B)))) + (6.00 x (Real((Integer A))))) degrees) facing CENTER
To explain, 20 from the first loop represents the number of elements per spire. 7 from the second loop represents the number of spires.

What does he mean 'elements'? The first equation is to find out how far the spiral should be from the position of the center right? Why does he multiply 8 by integer A? He divides 360 by 7 because there's 7 'lines' that move from the center? What's with the 6 near the end of the equation?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
1) An element is a part of the whole. Here, that means those missiles (there will be 20 missiles per spire).
2) The "100" is the base distance from the spire to the center, the "8 x Integer A" is the offset for each individual element of that spire to the center (the higher elements will be further away).
3) The multiplication by 8 is just an offset: the higher this number, the more spread-out the spiral will be.
4) The 6 near the end of the equation is similar to the 8 mentioned above. This time, it determines how quickly the spiral turns (note that this is in degrees, so it's far more sensitive than the offset-variable).

You can fiddle with 8 and 6 until you find a spiral you like.

Additional Notes:
- Try not to use Integer A/B: there are some known issues regarding them.
Create your own integer variables (such as LoopInt1 and LoopInt2) and loop those instead.
- Remove the location leaks.

  • Actions
    • -------- Setup --------
    • Set ElementsPerSpire = 20
    • Set AmountOfSpires = 8
    • Set BaseOffset = 50.00
    • Set ElementOffset = 16.00
    • Set ElementTurnAngle = 5.00
    • Set TempLoc1 = (Center of (Playable map area))
    • -------- Create Spire --------
    • For each (Integer LoopInt1) from 1 to ElementsPerSpire, do (Actions)
      • Loop - Actions
        • For each (Integer LoopInt2) from 1 to Spires, do (Actions)
          • Loop - Actions
            • Set TempLoc2 = (TempLoc1 offset by (BaseOffset + (ElementOffset x (Real(LoopInt1)))) towards (((360.00 / (Real(AmountOfSpires))) x (Real(LoopInt2))) + (ElementTurnAngle x (Real(LoopInt1)))) degrees)
            • Unit - Create 1 Dummy for Player 1 (Red) at TempLoc2 facing Default building facing degrees
            • Custom script: call RemoveLocation(udg_TempLoc2)
    • Custom script: call RemoveLocation(udg_TempLoc1)
 
Level 3
Joined
Sep 9, 2009
Messages
658
^ It's Daelin's static shapes tutorial. And Apocalypse that clears things up. But do you really have to use loops when you want to make spirals? What about just doing them via periodic triggers? Oh and I've got some questions regarding this trigger as well.

  • Unit Start Channling
    • Events
      • Unit - A unit Begins channeling an ability
    • Conditions
      • (Ability being cast) Equal to Frost Arrow Placement
    • Actions
      • Set dd_Caster = (Triggering unit)
      • Set dd_CasterOwner = (Owner of dd_Caster)
      • Set dd_CasterPos = (Position of dd_Caster)
      • Set dd_SpellLevel = (Level of Frost Arrow Placement for dd_Caster)
      • Set dd_Angle = 0.00
      • Set dd_UnitArray = 1
      • Set dd_EnemyGroup = (Units of type No unit-type)
      • Set dd_Distance = 0
      • Trigger - Turn on Unit Creates Effect <gen>
  • Unit Creates Effect
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set dd_Angle = (dd_Angle + 1.00)
      • Unit - Make dd_Caster face ((Facing of dd_Caster) + 90.00) over 0.00 seconds
      • Special Effect - Create a special effect at (dd_CasterPos offset by 200.00 towards (Facing of dd_Caster) degrees) using Abilities\Spells\Other\CrushingWave\CrushingWaveDamage.mdl
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Integer(dd_Angle)) Equal to (6 x dd_UnitArray)
        • Then - Actions
          • Unit - Create 1 dd_ArtUnit for dd_CasterOwner at (dd_CasterPos offset by 200.00 towards (Facing of dd_Caster) degrees) facing Default building facing degrees
          • Set dd_ArtUnit[dd_UnitArray] = (Last created unit)
          • Set dd_UnitArray = (dd_UnitArray + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Integer(dd_Angle)) Equal to 38
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Animation - Play dd_Caster's stand victory animation
          • Trigger - Turn on Unit Triggers Damage <gen>
        • Else - Actions
  • Unit Triggers Damage
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set dd_Distance = (dd_Distance + 25)
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Special Effect - Destroy dd_EffectArt
          • Unit - Move dd_ArtUnit[(Integer A)] instantly to ((Position of dd_ArtUnit[(Integer A)]) offset by -25.00 towards ((Angle from (Position of dd_ArtUnit[(Integer A)]) to dd_CasterPos) + 45.00) degrees)
          • Special Effect - Create a special effect at (Position of dd_ArtUnit[(Integer A)]) using Abilities\Spells\Undead\FreezingBreath\FreezingBreathMissile.mdl
          • Set dd_EffectArt = (Last created special effect)
          • Unit Group - Pick every unit in (Units within 245.00 of (Position of dd_ArtUnit[(Integer A)]) matching (((((Matching unit) is alive) Equal to True) and (((Matching unit) is in dd_EnemyGroup) Equal to False)) and (((Matching unit) belongs to an enemy of dd_CasterOwner) Equal to True))) and do (Actions)
            • Loop - Actions
              • Unit - Cause dd_Caster to damage (Picked unit), dealing (0.00 + (70.00 x (Real(dd_SpellLevel)))) damage of attack type Spells and damage type Normal
              • Unit - Create 1 Dummy of All for dd_CasterOwner at dd_CasterPos facing Default building facing degrees
              • Unit - Add Icy Possesion (Dummy) to (Last created unit)
              • Unit - Set level of Icy Possesion (Dummy) for (Last created unit) to dd_SpellLevel
              • Unit - Add a 1.50 second Generic expiration timer to (Last created unit)
              • Unit - Order (Last created unit) to Human Sorceress - Slow (Picked unit)
              • Unit Group - Add (Picked unit) to dd_EnemyGroup
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • dd_Distance Equal to 400
        • Then - Actions
          • Special Effect - Destroy dd_EffectArt
          • Trigger - Turn off (This trigger)
          • For each (Integer A) from 1 to 6, do (Actions)
            • Loop - Actions
              • Special Effect - Create a special effect at (Position of dd_ArtUnit[(Integer A)]) using Abilities\Spells\Human\Thunderclap\ThunderClapCaster.mdl
              • Unit - Remove dd_ArtUnit[(Integer A)] from the game
          • Custom script: call DestroyGroup (udg_dd_EnemyGroup)
          • Custom script: call RemoveLocation (udg_dd_CasterPos)
        • Else - Actions
Then how come in loop trigger 2 of this spell, the maker has the offset set in a negative value but the spiral still moves outward? How do you know anyway if you need to have a negative offset or a positive offset? The + 45 is there to decide the angle at which the spiral turns, right?
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
But do you really have to use loops when you want to make spirals? What about just doing them via periodic triggers?
Loop in this case is not periodic. The GUI action loop integer from 1 to X basically immediately repeats actions in the loop and it is used to simplify action which you would repeat and only change its certain parameters.

The trigger below creates 8 units around 1 point:
  • Untitled Trigger 001
    • Actions
      • Set p = (Center of (Playable map area))
      • -------- ---------------------------------------------------------------------- --------
      • Set p2 = (p offset by 256.00 towards 0.00 degrees)
      • Unit - Create 1 Footman for Player 1 (Red) at p2 facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_p2)
      • Set p2 = (p offset by 256.00 towards 45.00 degrees)
      • Unit - Create 1 Footman for Player 1 (Red) at p2 facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_p2)
      • Set p2 = (p offset by 256.00 towards 90.00 degrees)
      • Unit - Create 1 Footman for Player 1 (Red) at p2 facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_p2)
      • Set p2 = (p offset by 256.00 towards 135.00 degrees)
      • Unit - Create 1 Footman for Player 1 (Red) at p2 facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_p2)
      • Set p2 = (p offset by 256.00 towards 180.00 degrees)
      • Unit - Create 1 Footman for Player 1 (Red) at p2 facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_p2)
      • Set p2 = (p offset by 256.00 towards 225.00 degrees)
      • Unit - Create 1 Footman for Player 1 (Red) at p2 facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_p2)
      • Set p2 = (p offset by 256.00 towards 270.00 degrees)
      • Unit - Create 1 Footman for Player 1 (Red) at p2 facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_p2)
      • Set p2 = (p offset by 256.00 towards 315.00 degrees)
      • Unit - Create 1 Footman for Player 1 (Red) at p2 facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_p2)
      • -------- ---------------------------------------------------------------------- --------
      • Custom script: call RemoveLocation(udg_p)
As you can see, first point is offset to 0 degrees, each successive point by additional 45 degrees.
Look at how lengthy it is, you can easily get lost and imagine how much work you would have to do if you decided that all spawn points should be rotated by additional 20 degrees, you wanted to create different units, etc.

Because in this case you only change angle in linear fashion, you can use loop for it:
  • Untitled Trigger 001
    • Actions
      • Set p = (Center of (Playable map area))
      • For each (Integer loop) from 1 to 8, do (Actions)
        • Loop - Actions
          • Set p2 = (p offset by 256.00 towards (45.00 x (Real(loop))) degrees)
          • Unit - Create 1 Footman for Player 1 (Red) at p2 facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_p2)
      • Custom script: call RemoveLocation(udg_p)
You can see how short and well-arranged the trigger is now, not to mention how little work you would have if you decided to make changes to it.

Also, the trigger immediately executes each action in the loop and repeat that process as many times as you set it, it doesn't wait "0,01" second before firing another action. Both triggers in my post do and are same, but one is easier for you to manage while the other is not.
 
Level 3
Joined
Sep 9, 2009
Messages
658
@Nichilus I think you misunderstood my question. What I meant was that if aside from using loops like For each Integer blah blah...could you also make spirals using triggers with periodic events? Because wouldn't using periodic events instead of loops be better if you wanted a unit to move in a spiral fashion?

And in relation to to that, I'm having trouble making a group of units move spirally relative to their position. How do you do that?
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
To MOVE units in spirall it's a Periodic lOop or timer.
To CREATE units in spiral, a Loop is better.

About Spirals think about a Point with offset
Code:
Angle = 0
Point1 = CenterOfCirce
Point 2 = Point 1 Offset by 500 towards angle


Asuming you want to move the unit in a circular shape, every 0.03 you change the angle of the Unit like:
Code:
Angle = Angle+1
Point 1 = Center of Circle
Point 2 = Point 1 Offset by 500 towards angle

That will make the unit move in a circular shape, 1 angle per seconds. At that rate (1 angle every 0.03) the unit should give almost 3/4 of the cicle to reach the starting point of the circle.

If you want the spiral form, you have to manipulate the offset. If you reduce it periodically the unit will move towards the center of the spiral. if you increase it, the unit will get further away.

Code:
Moving units inside:

Angle = Angle+1
Point 1 = Center of Circle
Offset = Offset - 1
Point 2 = Point 1 Offset by towards angle

Moving Units outside:
Angle = Angle+1
Point 1 = Center of Circle
Offset = Offset + 1
Point 2 = Point 1 Offset by towards angle

To move the units to the right, you increase angle. To move them to the left, you reduce angle.

Test and see what happens when you Enable/Disable the loop or change the direction (+1 is to the right. -1 is to the left).
 

Attachments

  • EspiralTest.w3x
    18.2 KB · Views: 50
Last edited:
Level 28
Joined
Sep 26, 2009
Messages
2,520
@Nichilus I think you misunderstood my question. What I meant was that if aside from using loops like For each Integer blah blah...could you also make spirals using triggers with periodic events? Because wouldn't using periodic events instead of loops be better if you wanted a unit to move in a spiral fashion?
Sorry, I was quite sleepy when I wrote it and got lost in what I wanted to point out.

Anyway, if you want to create a spiral effect on ground (like from flames), you should use loops action, those are as fast as it can be executed.

If you want to move a unit on the spiral/in spiral fashion, then yes, you should use a trigger that fires every 0,03 seconds.
 
Status
Not open for further replies.
Top