HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[Question] What's that trick...

02-19-2008, 04:54 AM#1
Tide-Arc Ephemera
that you use to manipulate a flying unit's height? I know it's add and remove an ability, I believe it may be one of the Druid of the Talon abilities, which can allow this.

Also, I heard something about not being able to set negative flying heights, is this according to the grid lines or the physical terrain height (which are probably the same thing).

Also, if I wanted to have something fly in a perfectly linear path, would I just set it's flying height (for example) to 600 - GetLocationZ(whatever)?

I may be back with more questions, but those are some matters I'd like to solve for now.

Slightly off topic and I'd also like assistance with, I forgot how to use radians, I know there's the use of bj_DEGTORAD but I can't remember which one (being x or y) uses sin and which one uses cos. A TINY JASS example of polar projections (basically moving/doing something at ANGLE with a DISTANCE, such as moving a unit) would be nice.

Thanks ahead!
02-19-2008, 05:34 AM#2
The Elite
just getting first spot, will reply shortly:

EDIT
Quote:
that you use to manipulate a flying unit's height? I know it's add and remove an ability, I believe it may be one of the Druid of the Talon abilities, which can allow this.
Check out my tutorial: http://www.wc3campaigns.net/showthread.php?t=97234

Quote:
Also, I heard something about not being able to set negative flying heights, is this according to the grid lines or the physical terrain height (which are probably the same thing).
physical terrain height...

Quote:
Also, if I wanted to have something fly in a perfectly linear path, would I just set it's flying height (for example) to 600 - GetLocationZ(whatever)?
you meen without changing height as the terrain changes height? You'll have to write alot of code for that....

Quote:
Slightly off topic and I'd also like assistance with, I forgot how to use radians, I know there's the use of bj_DEGTORAD but I can't remember which one (being x or y) uses sin and which one uses cos. A TINY JASS example of polar projections (basically moving/doing something at ANGLE with a DISTANCE, such as moving a unit) would be nice.

I'll try and put one together, will post one in a few minutes if i get one working....

EDIT i have little idea about radians lol... so ill just post the code for PolarProjectionBJ with a polar projection example which moves a unit 500 distance in 90 degrees

Collapse JASS:
    call SetUnitPositionLoc( peasant, PolarProjectionBJ(GetRectCenter(some_region), 500.00, 90.00) )

Collapse JASS:
function PolarProjectionBJ takes location source, real dist, real angle returns location
    local real x = GetLocationX(source) + dist * Cos(angle * bj_DEGTORAD)
    local real y = GetLocationY(source) + dist * Sin(angle * bj_DEGTORAD)
    return Location(x, y)
endfunction
02-19-2008, 05:40 AM#3
Tide-Arc Ephemera
Very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very useful my friend.

+ Rep
*prays that he doesn't have to spread...*

Now only "polar projections" and a few other things to go...
02-19-2008, 06:01 AM#4
Ammorth
Quote:
Originally Posted by Tide-Arc Ephemera
Also, if I wanted to have something fly in a perfectly linear path, would I just set it's flying height (for example) to 600 - GetLocationZ(whatever)?

Basically, yes. If you want to get technical, you can make the starting height (replacing the 600 height) with relativeheight + GetLocationZ() at the point you start the movement at. This will allow you to create a missile or whatever at a "relative height" in relation to the place it was created, so you can launch a missile from a unit, 100 height above it and it will appear just like that.

Also, for a quick lesson at trig, you should learn about SOH CAH TOA. Read the over-view section for a simplistic usage and lesson/examples.
02-19-2008, 06:30 AM#5
The Elite
oh btw yes, grid lines and physical terrain height are the same things
02-19-2008, 08:08 AM#6
Tide-Arc Ephemera
@ Ammorth
I lol'd when I saw SOH CAH TOA randomly because I'm so used to my maths teacher yelling that out when she's pissed off. Also it's on a poster in that room.

I'll edit this again when I've got something that's above 5% relevant.

EDIT!
Uh... I MAY sound lazy when I say this, but I do a lot better when I see an actual example... looking at theories like that confuse me ten bajillion times over.
02-19-2008, 11:35 PM#7
Ammorth
May contain errors, but you should get the jist:

Collapse JASS:
globals
    constant real height = 100. // height at launch
    constant real speed = 900. // speed
    constant real distance = 3000. // how far it will travel
    constant real timestep = 0.033 // how fast to update
    real missile_x
    real missile_y
    real missile_z // "true" x, y, z in relation to wc3's 3d space (not terrain)
    real missile_dist
    real missile_x_comp
    real missile_y_comp // x and y component of velocity (so you don't have to re-calculate)

    unit missile_unit

    location locZ = Location (0., 0.) // Used for custom function GetLocZ()
endglobals

function GetLocZ takes real x, real y, returns real
    call MoveLocation(locZ, x, y) // moving is faster than creating a new location and then destroying it
    return GetLocationZ(locZ)
endfunction

function callback takes nothing returns nothing
    local real z
    set missile_x = missile_x + missile_x_comp
    set missile_y = missile_y + missile_y_comp
    call SetUnitX(missile_unit, missile_x)
    call SetUnitY(missile_unit, missile_y)
    set z = missile_z - GetLocZ(missile_x, missile_y) // the flying height of the unit is the height after the terrain (to keep it in 3d space)
    call SetUnitFlyHeight(missile_unit, z, 0) // set the height of the unit
    set missile_dist = missile_dist + speed*timestep // add the distance traveled per time-step
    if missile_dist >= distance then // travelled the distance required
        call RemoveUnit(missile_unit)
        set missile_dist = 0
        set missile_x_comp = 0
        set missile_y_comp = 0 // set the "missile" to null
        call DestroyTimer(GetExpiredTimer())
    endif
endfunction

function Launch takes real x, real y, real angle returns nothing
    if missile_x_comp == 0 and missile_y_comp == 0 then
        return // already a missile
    endif
    // we want the x and y components.  To get them, we need trig ratios.
    // the angle and speed create a terminal arm at the origin of x, y
    // we want to find the x1, and y1 cord at the end of the arm; they are called components
    // no matter which way the arm is pointing, the x and y components will make a right angle on the x axis.
    // since this is true, we can use "SOH CAH TOA" to find the x and y components
    // since X is "opposite" of the angle, it uses Sin
    // since Y is "adjacent" of the angle, it uses Cos
    set missile_x_comp = speed*timestep*Cos(angle*bj_DEGTORAD) // convert the angle to rad, since thats what the native uses
    set missile_y_comp = speed*timestep*Sin(angle*bj_DEGTORAD)
    
    set missile_x = x
    set missile_y = y
    set missile_z = height + GetLocZ(x, y) // its initial height is 100 over the current terrain height (z then becomes the "true" height of the object, in relation to wc3's 3d space)
    set missile_unit = CreateUnit(Player(0), 'hfoo', x, y, 0.)
    call SetUnitX(missile_unit, x) //to make sure it appears there
    call SetUnitY(missile_unit, y) // same thing again
    call UnitAddAbility(missile_unit, 'Amrf') // add crow form (I hope id is correct)
    call UnitRemoveAbility(missile_unit, 'Amrf')
    call SetUnitFlyHeight(missile_unit, height, 0) // set fly height to initial height since it is already correct with out getlocz call, to the terrain.
    call TimerStart(CreateTimer(), timestep, true, function callback)
endfunction

Edit: couldn't find an image I liked and couldn't figure out how to make it
I also changed some stuff in the code (missed some things and typed degrees instead of radians).
02-20-2008, 04:38 AM#8
Tide-Arc Ephemera
*applauds and gawks in awe*

That was WAY useful. It pretty much covers EVERYTHING I was asking for, too!

+Rep!
02-20-2008, 06:56 AM#9
Ammorth
I just posted to say I updated.

...

I just posted to say how much I care.