• 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] Triggered projectiles and unit height?

Status
Not open for further replies.
Level 16
Joined
Dec 15, 2011
Messages
1,423
You need to use this Jass function to get the height difference then with each missile movement, change its height by height difference/loop count (0.03s will get a loop count of 33)

JASS:
function GetUnitHeightDifference takes unit u1, unit u2 returns real
local location l1 = GetUnitLoc (u1)
local location l2 = GetUnitLoc (u2)
local real r1 = GetLocationZ (l1)
local real r2 = GetLocationZ (l2)

call RemoveLocation (l1)
call RemoveLocation (l2)

return (r1 + GetUnitFlyHeight (u1)) - (r2 + GetUnitFlyHeight (u2))
endfunction

Use it like this in the cast phase of the spell. HeightChange is a real var.

  • Custom script: set udg_HeightChange = GetUnitHeightDifference (udg_Target, udg_Missile)
It may return negative if the missile is higher than the unit. Also, changing height of either unit midflight will cause this to malfunction. You should note that.
 
Last edited:
Level 3
Joined
Sep 9, 2009
Messages
658
You can get the target's flying height and then calculate the change in flying height of the projectile per interval based on the distance.

How do you do the calculations? Or rather how do you get the formula?

You need to use this Jass function to get the height difference then with each missile movement, change its height by height difference/loop count (0.03s will get a loop count of 33)

JASS:
function GetUnitHeightDifference takes unit u1, unit u2 returns real
local location l1 = GetUnitLoc (u1)
local location l2 = GetUnitLoc (u2)
local real r1 = GetLocationZ (l1)
local real r2 = GetLocationZ (l2)

call RemoveLocation (l1)
call RemoveLocation (l2)

return (r1 + GetUnitFlyHeight (u1)) - (r2 + GetUnitFlyHeight (u2))
endfunction

Use it like this in the cast phase of the spell. HeightChange is a real var.

  • Custom script: set udg_HeightChange = GetUnitHeightDifference (udg_Missile, udg_Target)
It may return negative if the missile is higher than the unit. Also, changing height of either unit midflight will cause this to malfunction. You should note that.

So I get the height difference using the custom script, divide it by the loop which is .03 and add the answer to that to the missile's height? Am I getting this right?

EDIT: I tried the custom script, and it's giving me two errors. Undeclared function GetUnitHeightDifference and Cannot convert null to real.
 
Level 3
Joined
Sep 9, 2009
Messages
658
  • Glacial Blast Loop
    • Events
      • Time - Every 0.04 seconds of game time
    • Conditions
    • Actions
      • Custom script: set udg_HeightChange = GetUnitHeightDifference (udg_GB_unit[1], udg_GB_dummy)
      • Set GB_real = (HeightChange / 25.00)
      • Set GB_speed = 1150.00
      • Set GB_loc[1] = (Position of GB_dummy)
      • Set GB_loc[2] = (Position of GB_unit[1])
      • Set GB_loc[3] = (GB_loc[1] offset by (GB_speed x 0.04) towards (Angle from GB_loc[1] to GB_loc[2]) degrees)
      • Unit - Move GB_dummy instantly to GB_loc[3]
      • Animation - Change GB_dummy flying height to GB_real at 100.00
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between GB_loc[2] and GB_loc[1]) Less than or equal to 100.00
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Unit - Kill GB_dummy
          • Unit - Cause GB_unit[0] to damage GB_unit[1], dealing GB_damage damage of attack type Chaos and damage type Universal
          • Custom script: call RemoveLocation (udg_GB_loc[1])
          • Custom script: call RemoveLocation (udg_GB_loc[2])
          • Custom script: call RemoveLocation (udg_GB_loc[3])
        • Else - Actions
          • Custom script: call RemoveLocation (udg_GB_loc[1])
          • Custom script: call RemoveLocation (udg_GB_loc[2])
          • Custom script: call RemoveLocation (udg_GB_loc[3])
I got the custom script to work but the dummy still won't fly. I've attached my loop trigger above. Can anyone tell me what's wrong with it?
 
Level 3
Joined
Sep 9, 2009
Messages
658
So I need to make another real variable?

EDIT: Oh, wait. I think I get what you mean now. I'll work on it as soon as my laptop cools down.

  • Glacial Blast Loop
    • Events
      • Time - Every 0.04 seconds of game time
    • Conditions
    • Actions
      • Custom script: set udg_HeightChange = GetUnitHeightDifference (udg_GB_dummy, udg_GB_unit[1])
      • Set GB_real = (HeightChange / 25.00)
      • Set GB_speed = 1150.00
      • Set GB_loc[1] = (Position of GB_dummy)
      • Set GB_loc[2] = (Position of GB_unit[1])
      • Set GB_loc[3] = (GB_loc[1] offset by (GB_speed x 0.04) towards (Angle from GB_loc[1] to GB_loc[2]) degrees)
      • Unit - Move GB_dummy instantly to GB_loc[3]
      • Unit - Add Crow Form to GB_dummy
      • Animation - Change GB_dummy flying height to ((Current flying height of GB_dummy) + GB_real) at 100.00
      • Unit - Remove Crow Form from GB_dummy
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between GB_loc[2] and GB_loc[1]) Less than or equal to 100.00
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Unit - Kill GB_dummy
          • Unit - Cause GB_unit[0] to damage GB_unit[1], dealing GB_damage damage of attack type Chaos and damage type Universal
          • Custom script: call RemoveLocation (udg_GB_loc[1])
          • Custom script: call RemoveLocation (udg_GB_loc[2])
          • Custom script: call RemoveLocation (udg_GB_loc[3])
        • Else - Actions
          • Custom script: call RemoveLocation (udg_GB_loc[1])
          • Custom script: call RemoveLocation (udg_GB_loc[2])
          • Custom script: call RemoveLocation (udg_GB_loc[3])
Okay, I guess I still don't get it. I tried applying your changes and I even added the crow form to the dummy but it still won't change its height.
 
Last edited by a moderator:
Level 3
Joined
Sep 9, 2009
Messages
658
Now it works! Thank you! But just one last thing. If I have to set the flying height to zero, then the dummy sticks to the ground, which makes it look weird when targeting ground enemies. Is it alright if I add some fly height to the dummy once it's created but before the height difference is calculated?

EDIT: Oh, wait I can't do that right? Otherwise the dummy will go downward instead of keeping the same height. Is there another way to go about it?

2nd EDIT: Actually, never mind. I tried a if/then/else action and it works. Thanks again!
 
Status
Not open for further replies.
Top