• 🏆 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!

Lightning Effect and Slopes

Status
Not open for further replies.
I have a little problem with lightning effect on slopes that was not connecting with a unit even tho I set it's Z height to the same as the unit it's emitting from. I was told I had to adjust for GetLocationZ, which I did, but now I think it's leaking a location variable. I would like to avoid having to use any location variables if necessary and deal strictly with reals. can anyone help? Here's my current code:

call MoveLightningEx(udg_BeamLightning[ID], true, GetUnitX(udg_BeamCaster[ID]), GetUnitY(udg_BeamCaster[ID]), GetLocationZ(GetUnitLoc(udg_BeamCaster[ID])) + z1, GetUnitX(udg_BeamMover[ID]), GetUnitY(udg_BeamMover[ID]), GetLocationZ(GetUnitLoc(udg_BeamMover[ID])) + z2)

z1 and z2 are the flying heights of udg_BeamCaster[ID] and udg_BeamMover[ID] respectively.

This works as intended, but yeah, possible leak + not wanting to use locations. This event is supposed to repeat every 0.3125 seconds, multiple times. So the least overhead is the most preferred.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
You have to use locations since there is no coordinate alternative for GetLocationZ, store locations in variables and remove+nullify them after.

Better solution is using a global location variable and moving it to postion which you want to get Z value instead of creating/destroying locations everytime.
 
I think I can help.

You need the terrainZ.

Here is how I did it. I make no claim that this is perfect, and I am removing all of the other stuff going on with the spell to just focus on the Z issue.

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • Then - Actions
      • Set AV_X1 = (X of AV_Loc)
      • Set AV_X2 = (X of AV_LocOffset)
      • Set AV_Y1 = (Y of AV_Loc)
      • Set AV_Y2 = (Y of AV_LocOffset)
      • Custom script: set udg_AV_Z1 = GetLocationZ(udg_AV_Loc)
      • Custom script: set udg_AV_Z2 = GetLocationZ(udg_AV_LocOffset)
      • Custom script: call MoveLightningEx(udg_AV_LightningFx[udg_AV_Loop_X], true, udg_AV_X1, udg_AV_Y1, udg_AV_Z1, udg_AV_X2, udg_AV_Y2, udg_AV_Z2)
See also, this link.
 
NEW PROBLEM

Slopes work, but I had forgotten about cliffs and water. Consider the screenshots, the lightning effects do not align vertically with the dummy units. I tried multiple movement types on the dummies (the dummies in the screnshots - the glowing green orbs - have a flying movement type), and it sometimes aligned, but then the dummies would fly up and down the slopes to adjust to the new heights, and no movement type allowed alignment over both water and cliff.

Any idea how I can fix this?
 

Attachments

  • sc2.jpg
    sc2.jpg
    149.5 KB · Views: 134
  • sc3.jpg
    sc3.jpg
    270.5 KB · Views: 111
So I found out the reason why the lightning effect was borking, and it's because a unit's flying height does not properlly return it's z-axis from the terrain because flying units move up/down cliff without their flying height getting updated. Unfortunately GetLocationZ + UnitFlyHeight doesn't account for cliffs and water levels.

Can anybody help? I ready to move on to vJASS at this point (I'd rather not, so that the system is available for people who don't use JNGP, but if the lightning effect is going to fail so miserably on cliffs and water, I can make that concession)
 
Level 11
Joined
Dec 19, 2012
Messages
411
There present 1 native which could check the terrain cliff level,
native GetTerrainCliffLevel takes real x, real y returns integer
Using this native for checking cliff level, and adding additional height according to cliff height probably could works.
 
It works! Kinda sucks that I have to make my system need JNGP, but if that's what it takes to make the lightning connect properly then so be it.

Are you going to add a water level check to this eventually? That's the only place the lightning it not working.

EDIT: Right, tested the movement types a bit more. Fly tends to work best on cliffs, but there's a noticeable gap when over water. I've also been getting some weird height issues on narrow cliffs where it shoots over a ground unit (thought that's because it's connecting to a flying unit, so not really a problem of the system). Hover/Amphibious/Float work well, but have trouble keeping up with flying units near/on cliffs since, well, they're not Fly movement type.
 
Last edited:
Level 6
Joined
Jun 18, 2004
Messages
119
It works! Kinda sucks that I have to make my system need JNGP, but if that's what it takes to make the lightning connect properly then so be it.
I don't understand why people would not use JNGP always, but anyway, its rather simple to rewrite my system if you want, all the math is done in a single function anyway.

I plan on adding water to it some time soon.
 
I use JNGP all the time, it's just that I've encountered people who just don't want to use it. It's mostly to reach the most people, but for my part, I love JNGP :p

I've been tweaking my system a bit more and I'm ended up having to use two dummies with passive transformation to switch from hover to flying movement type, which honestly just feel like a stupid thing to do. It doesn't fix the problem completely either, and I can't use MissileRecycler with that setup either. Lemme know when you've added water height to GetUnitZ, i'll be happy to test it out.
 
I am at my wit's end with this nonesense. Lightning effects and units interract with terrain in different ways, and even with GetUnitZ or ZLibrary I can't get either to connect properly. While the dummy units that carry the lightning effects will most of the time correctly have the proper actual Z axis of the flying unit in question, lightning effects will just do w/e they want.

If anyone knows of a lightning system that can properly account for terrain/cliff/water level and connect two units together, please let me know. The only solution I can think of is to drop lightning effects altogether and use a dummy ability like Finger of Death. Even then I don't know if they lightning effect will connect properly, not to mention the headache-inducing clusterfuck of having to make the mover dummy unit targetable but unselectable with some chaos/locust bs that I don't even remember how to do.
 
Level 7
Joined
Oct 19, 2015
Messages
286
What kind of movement type are you using for your dummy units? I am using "hover" (same as used by Wisp, for example) and am able to lock a lightning to it just fine, over both water and cliffs. This is the code I use for lightning coordinates:

JASS:
            real x = GetUnitX( u );
            real y = GetUnitY( u );
            real z = GetUnitFlyHeight( u );
            MoveLocation( loc, x, y );
            z += GetLocationZ( loc );

This should work, unless your terrain has some features that mine doesn't, but I have no idea what they could be, like I said, I tested over both water and cliffs.
 
I tried that already (tested with every movement type), and it didn't work then and it's not working now, unfortunately :(

Here's where I set the lightning's Z:
JASS:
    call MoveLocation(udg_Beam_TerrainZ_1,GetUnitX(udg_BeamCaster[ID]),GetUnitY(udg_BeamCaster[ID]))
    call MoveLocation(udg_Beam_TerrainZ_2,GetUnitX(udg_BeamMover[ID]),GetUnitY(udg_BeamMover[ID]))
            
    set AbsZ1 = GetLocationZ(udg_Beam_TerrainZ_1) + GetUnitFlyHeight(udg_BeamCaster[ID])
    set AbsZ2 = GetLocationZ(udg_Beam_TerrainZ_2) + GetUnitFlyHeight(udg_BeamMover[ID])

    if udg_BeamLightning[ID] != null then
        call MoveLightningEx(udg_BeamLightning[ID], true, GetUnitX(udg_BeamCaster[ID]), GetUnitY(udg_BeamCaster[ID]), AbsZ1, GetUnitX(udg_BeamMover[ID]), GetUnitY(udg_BeamMover[ID]), AbsZ2)
    endif

I don't recognise the syntax in your code though. Is that Zinc?

EDIT: Progress was had! It turns out that my locations, for some reason, were not being created, so GetLocationZ was returning 0.00. This fixes the problem of the dummies that were not connecting properly with their targets. However, the lightning effects still are doing just whatever. It would seem they have their own z-axis that's independent of a unit's z-axis, or something. GetLocationZ + GetUnitFlyHeight will still have the lightning effect stay a bit below the dummies.
 
Last edited:
Level 7
Joined
Oct 19, 2015
Messages
286
In my test the lightning also wasn't perfectly centred on the unit, I just assumed that was because the model I was using might not be properly centred on its origin. Even if there is a different reason, in my test the lightning offset was very small and constant so this should be solvable with a constant offset added to the z value.

Yes, that's Zinc.
 
Status
Not open for further replies.
Top