How can I make a flying unit maintain its height when going over increased terrain?

EqualiseR

New Member
Reaction score
1
I'm currently working on a map in which you have an airplane as your unit, and you control it with arrow keys, however, whenever I go over locations with higher terrain, my airplane automatically adjusts its height (making the airplane higher).

Does anyone know how to make it where no matter how high the terrain in front of you is, the airplane will maintain its distance from the ground and if need be, crash into the higher terrain?

Because basically, I want the player to have to control the airplanes height (by pressing up / down), but this is useless if the game does it for you.


Any help would be greatly appreciated.
~EqualiseR
 

NeuroToxin

New Member
Reaction score
46
You must wait 24 hours before bumping. Anyways, Im not sure, there might be a native of GetTerrainHeight.
 

canons200

New Member
Reaction score
50
you can't, that is the unit walking setting, default setting by blizzard. Unless you hack it.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Does anyone know how to make it where no matter how high the terrain in front of you is, the airplane will maintain its distance from the ground and if need be, crash into the higher terrain?
Since you're using arrow key control, I presume you're "sliding" the plane? That helps things.

There's a native, [ljass]GetLocationZ(whichLocation)[/ljass], that gets the terrain height at a location. A unit's flying height is always relative to the terrain height, so to keep its absolute elevation level, you can alter the plane's flying height based on the difference between the terrain height where it is presently located, and where it's about to be moved in your sliding trigger.

You can find implementations of this in just about every projectile system, if you're a learn-by-example type.

One note: it's movement type cannot be Fly. Flying units have a gradual slope around cliff edges and trees that can't be detected or altered by triggers and will prevent keeping a level altitude. Instead, I'd suggest using Hover and making sure the unit doesn't have collision.
 

EqualiseR

New Member
Reaction score
1
I tried using a GetLocationZ position of unit X and all it did was represent the coordinate Z of the map.

Anyways, I'm basically looking for a way to get the terrain height at the position of a unit and then create a trigger such as:

Event- Every 0.05 seconds of game time

Actions-Animation- Set Flying Height of Unit X (Airplane) to Current Flying Height of Airplane minus TerrainHeight (Variable representing Terrain Height at position of unit X)


Can anyone tell me how to get the terrain height at the position of a unit?

Thank you,
EqualiseR :)
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
I'm quite confused by your post.

I tried using a GetLocationZ position of unit X and all it did was represent the coordinate Z of the map.
Yes, isn't that what you want?

Anyways, I'm basically looking for a way to get the terrain height at the position of a unit
...which is what you just said you had...

and then create a trigger such as:

Event- Every 0.05 seconds of game time

Actions-Animation- Set Flying Height of Unit X (Airplane) to Current Flying Height of Airplane minus TerrainHeight (Variable representing Terrain Height at position of unit X)

Can anyone tell me how to get the terrain height at the position of a unit?
Trigger:
  • Level Flight
    • Event
      • Time - Every 0.05 seconds of game time
    • Actions
      • Set TempPoint = Position of Airplane
      • Custom script: set TempReal = GetLocationZ(udg_TempPoint)
      • Animation - Set Flying Height of Airplane to (DesiredConstantHeight - TempReal) at rate 0
      • Custom script: call RemoveLocation(udg_TempPoint)
 

EqualiseR

New Member
Reaction score
1
Thank you, and I had to modify it because it was constantly reducing the flying height of the airplane every 0.05 seconds, and even now that I fixed that part, my airplane isnt flying smoothly, its flying height keeps constantly changing when going over increased / decreased terrain areas.


Do you know how to fix this? Or is there a different method or trigger I could use to make the airplane fly straight always and completely ignore terrain height changes?

Thank you,
EqualiseR
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
my airplane isnt flying smoothly, its flying height keeps constantly changing when going over increased / decreased terrain areas.

Do you know how to fix this?
Is it like a jagged jerkiness when passing over a cliff's edge? If so, I suspect it's what I mentioned before:
One note: it's movement type cannot be Fly. Flying units have a gradual slope around cliff edges and trees that can't be detected or altered by triggers and will prevent keeping a level altitude. Instead, I'd suggest using Hover and making sure the unit doesn't have collision.
 

EqualiseR

New Member
Reaction score
1
I tried changing the airplane's movement type to Hover, with the collision set as 0, but now I am unable to raise / decrease the airplane's altitude by using 'Animation - Change Airplane Flying Height to X at rate 0' due to the fact that it only works with flying unit types. Thusly, my unit is maintaining its default specified altitude and is stopping everytime it runs into increased terrain.

How would I go about fixing it, or what trigger would allow me to change the 'Hover Height' of the airplane, as well as make it maintain an altitude without being jerky?

Thank you,
EqualiseR
 

tommerbob

Minecraft. :D
Reaction score
110
I think you could add/remove the crow form ability. It's a well known WC3-bug that is used for jump and leap spells.
 

EqualiseR

New Member
Reaction score
1
I think you could add/remove the crow form ability. It's a well known WC3-bug that is used for jump and leap spells.

That worked as far as letting me increase / decrease the hover height, however it did not change the fact that I am still crashing into the increased / higher terrain. Only now, I am crashing into it even though I am far above it :p

Anyone know how to fix this?

Thank you,
EqualiseR
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Define "crashing into it"... :p

At this point, I think we need to see your triggers.
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
Define "crashing into it"... :p

At this point, I think we need to see your triggers.
and probably the unit data too


edit: when you say crash, are you saying the unit is colliding with the cliff and can't fly over it?
 

EqualiseR

New Member
Reaction score
1
Yes sorry, by crashing I meant it is unable to fly over (even when it is hovering way above the terrain level in front of the airplane).

By the looks of it, it doesn't seem like hovering is working, so I have reverted it back to flying, and now my only problem is that it's very jerky and the plane is constantly changings it altitude via the triggers rather than maintaining an altitude.


Here is the trigger / unit information:


Note: 'J-10 0000 <gen>' refers to the airplane.


Here is the trigger I have used to hopefully prevent the airplane from letting terrain height changes affect the airplane's flying height.

Trigger:
  • Flight Control Copy 2
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Set TempPoint = (Position of J-10 0000 &lt;gen&gt;)
      • Custom script: set udg_TempReal = GetLocationZ(udg_TempPoint)
      • Animation - Change J-10 0000 &lt;gen&gt; flying height to ((Real(Red_MaintainFlyingHeight_integ)) - TempReal) at 0.00
      • Custom script: call RemoveLocation(udg_TempPoint)


The variable 'Red_MaintainFlyingHeight_integ' is an integer variable I made to follow the flying height of the airplane ONLY when the player presses the Up Arrow or Down Arrow, and ignore flying height changes that the trigger above applies. This prevents the trigger above from constantly reducing the airplane's height to "((Current flying height of J-10 0000 <gen>) - TempReal) at 0.00" every 0.05 seconds, because when I tried it that way my airplane would ALWAYS stay at ground level when flying over increased terrain height areas.


Here are the triggers I use to set the 'Red_MaintainFlyingHeight_integ' as well as the flying height of the airplane only when pressing up/down arrows:


--- Increase Flying Height ---

Trigger:
  • Red increase Altitude
    • Events
      • Time - Every 0.02 seconds of game time
    • Conditions
      • (Current flying height of J-10 0000 &lt;gen&gt;) Less than or equal to 700.00
      • Red_UpArrowKey Equal to 1
    • Actions
      • Set Red_MaintainFlyingHeight_integ = (Red_MaintainFlyingHeight_integ + 7)
      • Animation - Change J-10 0000 &lt;gen&gt; flying height to (Real(Red_MaintainFlyingHeight_integ)) at 0.00


--- Decrease Flying Height ---

Trigger:
  • Red Decrease Altitude
    • Events
      • Time - Every 0.02 seconds of game time
    • Conditions
      • (Current flying height of J-10 0000 &lt;gen&gt;) Greater than or equal to 100.00
      • Red_DownArrowKey Equal to 1
    • Actions
      • Set Red_MaintainFlyingHeight_integ = (Red_MaintainFlyingHeight_integ - 7)
      • Animation - Change J-10 0000 &lt;gen&gt; flying height to (Real(Red_MaintainFlyingHeight_integ)) at 0.00



And last of all, the unit data for the Airplane (Only modified data).

---
Abilities - Normal: (None)
Art - Model File: (My imported jet model)
Combat - Attacks Enabled: None
Combat - Targeted as: Air
Movement - Height: 300.00
Movement - Speed Base: 0
Movement - Type: Fly (I can always change this to hover if need be)
Pathing - Collision Size: 0.00




Sorry this was so long, I wanted to include everything that might be helpful so you guys have an understanding of what is going on in my triggers. I can also upload my map if need be.

Thank you :)
EqualiseR
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Yes sorry, by crashing I meant it is unable to fly over (even when it is hovering way above the terrain level in front of the airplane).
Well, that depends on your movement trigger, which you didn't post. :eek:

As far as I know, it's impossible to get level flight over cliffs with a unit set to "Fly", so you need a way to not collide with cliffs while set to "Hover". Can you post your movement trigger(s)?
 

EqualiseR

New Member
Reaction score
1
Well, I am succesfully getting the terrain height with the movement type as fly, but I can tell it is still wobbly now that I supposedly fixed it. The trigger is in place properly, but it is still wobbly and not smooth. I have the camera set to act as a first person shooter camera, and I can tell the camera is contributing to the wobbliness, but so is the airplane itself.

Here is the 'Move trigger'. - Unfortunately, it is in JASS so I'll brief you just incase you don't understand it.


function Trig_Red_Move_Actions takes nothing returns nothing
call SetUnitPositionLoc( gg_unit_nstw_0000, PolarProjectionBJ(GetUnitLoc(gg_unit_nstw_0000), 9.00, GetUnitFacing(gg_unit_nstw_0000)) )
call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ROTATION, GetUnitFacing(gg_unit_nstw_0000), 0.00 )
call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(gg_unit_nstw_0000), 0.00 )
endfunction

//===========================================================================
function InitTrig_Red_Move takes nothing returns nothing
set gg_trg_Red_Move = CreateTrigger( )
call DisableTrigger( gg_trg_Red_Move )
call TriggerRegisterTimerEventPeriodic( gg_trg_Red_Move, 0.01 )
call TriggerAddAction( gg_trg_Red_Move, function Trig_Red_Move_Actions )
endfunction


Basically what this does is move the airplane forward by '9.00' every 0.01 seconds, as well as adjusts the camera to turn with the airplane and stay at the same height as the airplane.


Thank you for your help,
Equaliser
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
call SetUnitPositionLoc( gg_unit_nstw_0000, PolarProjectionBJ(GetUnitLoc(gg_unit_nstw_0000), 9.00, GetUnitFacing(gg_unit_nstw_0000)) )
FYI, you're leaking two points here, GetUnitLoc() and PolarProjectionBJ().

Anyway, instead use SetUnitX(whichUnit, X) and SetUnitY(whichUnit, Y). Those functions ignore collision, such as when trying to go over a cliff.

It'd suggest:
JASS:

local location l1 =  GetUnitLoc(gg_unit_nstw_0000)
local location l2 = PolarProjectionBJ(l1, 9.00, GetUnitFacing(gg_unit_nstw_0000))

call SetUnitX( gg_unit_nstw_0000, GetLocationX(l2))
call SetUnitY( gg_unit_nstw_0000, GetLocationY(l2))
call RemoveLocation(l1)
call RemoveLocation(l2)
set l1 = null
set l2 = null


As for the wobbliness, it'd be easier to diagnose with a map to try. Text can be insufficient to describe the problem. :eek:
 

educator

New Member
Reaction score
9
i did something like this, the terrain height of a single block ( like from 0 to 1) is about 127 in terms of a units flying height, so if it goes up, decrease its flying height by 127, if it goes down, increase its flying height by 127,then if the units flying height is less than or equal to 127 x terrain height, they crash and die. (btw, yes, I am a noob, and all other suggestions seem ultra complex to me)
 
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