HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Calculating Z

11-21-2008, 09:14 PM#1
Rheias
Well, I'm trying to make a unit move up and down the Z axis while moving. So say I order it to move to a new location, it should go up or down (so fly height increases/decreases while the movement). The question is, what is the correct math equation to do that?

You know what is the Z height in the first location, the Z Angle is (0 being you go straight up, 180 straight down) and the distance between the points. All we need to figure out is the Z in the location.

Clear enough I hope?

All help would be appreciated!
Thanks!
11-21-2008, 09:18 PM#2
xombie
There is a JASS function called GetLocationZ and all you would need to do is get the unit's x/y coordinates. From there you would add the unit's flying height (GetUnitFlyHeight).
11-21-2008, 09:25 PM#3
Rheias
I'm sorry I think you may have misunderstood me. This is purely a mathematical question. What I'm doing is using 3D coordinates in my map. In other words, I got units that can increase/decrease their flying height.

So, we can create an imaginative 3D triangle to display their movement. On that triangle (or pyramid) a unit moves from one point to another. In the new point the X,Y and Z values change. Now, it is not hard to calculate X's and Y's new value, using the angle and distance.

NewX = OldX + Distance * Cos(Angle * bj_DEGTORAD)
NewY = OldY + Distance * Sin(Angle * bj_DEGTORAD)

Now, calculating Z is a whole other story. I have the same parameters, I know the angle (note, IT IS different than X's/Y's angle) and the distance between the two points. All I'm left to calculate is the NewZ. So:

NewZ = ?

Clear now I hope?

Thanks!
11-21-2008, 09:26 PM#4
Limb_Smasher
To me, it's not clear if you're asking to just get the Z of the unit, or if you want to set the Z of a unit in terms of some known variables.

If you want the Z, then Xombie's got the correct idea.
However, if you're looking for a sort of function to set the Z for a unit, gonna need some more info.

Hope this helps

EDIT: This is in response to your first post; mustve posted your new one right before mine.
11-21-2008, 09:36 PM#5
Rheias
> However, if you're looking for a sort of function to set the Z for a unit, gonna need some more info.

Alright, basically we got this:

Trigger:
Click Up
Collapse Events
Player - Player 1 (Red) Presses the Up Arrow key
Player - Player 2 (Blue) Presses the Up Arrow key
Conditions
Collapse Actions
Set UpDown[(Player number of (Triggering player))] = 0.40

Trigger:
Click Down
Collapse Events
Player - Player 1 (Red) Presses the Down Arrow key
Player - Player 2 (Blue) Presses the Down Arrow key
Conditions
Collapse Actions
Set UpDown[(Player number of (Triggering player))] = -0.40

Trigger:
Release Up Down
Collapse Events
Player - Player 1 (Red) Releases the Up Arrow key
Player - Player 1 (Red) Releases the Down Arrow key
Player - Player 2 (Blue) Releases the Down Arrow key
Player - Player 2 (Blue) Releases the Up Arrow key
Conditions
Collapse Actions
Set UpDown[(Player number of (Triggering player))] = 0.00

What this does just let's me know if the player is pressing up, down or none. If he is pressing up I increase the Z angle, if he is pressing down I decrease it. Now we are running a timer, every tick we want to move the unit up or down the Z axis according to the triggers above.

So, here is the code (deleting some irrelevant parts):

Collapse JASS:
globals
    integer Players = 2
    unit array Hero
    real array Vangle
endglobals

function callback takes nothing returns nothing 
    local integer i = 1
    local real z
    local real nz
    
    loop
        exitwhen i > Players

        set z = GetUnitFlyHeight(Hero[i])
        set Vangle[i] = Vangle[i] + udg_UpDown[i]
        set nz = ??
        
        set i = i + 1
    endloop
endfunction
11-21-2008, 09:37 PM#6
Limb_Smasher
Would a cylindrical coordinate system be of help?

Gives you position in terms of a Radius (distance), a Theta (angle), and a Z.

EDIT: man i keep post right after you, so I don't get to read your latest post.
11-21-2008, 09:40 PM#7
Rheias
Perhaps, it couldn't hurt taking a look at one, though I think we are complicating stuff a bit. I'm sure there is a simple equation for what I'm asking that I'm simply not aware of.

Thanks for helping. :)

Edit: Going here I found some information, yet the exact equation isn't written there.
11-21-2008, 09:53 PM#8
Limb_Smasher
OK, so you want a new Z with respect to the desired angle and distance.

If we're moving in a straight line, can't you do this:

tan(angle) = height / distance

so you know the angle and distance, now you can calculate the height.

is that what youre looking for?
11-21-2008, 11:36 PM#9
Anitarf
I couldn't have possibly guessed from your original post that you were trying to do what you are trying to do. Only now that I've seen the code is it clear.

Anyway, if you could figure it out in one dimension, why is it so difficult to apply the same thing in the other, namely this:
Quote:
NewX = OldX + Distance * Cos(Angle * bj_DEGTORAD)
NewY = OldY + Distance * Sin(Angle * bj_DEGTORAD)
If pitch is your angle between the z axis and the xy plane then:

NewZ = OldZ + Distance * Sin(pitch * bj_DEGTORAD)
DeltaXY = Distance * Cos(pitch * bj_DEGTORAD)
NewX = OldX + DeltaXY * Cos(facing * bj_DEGTORAD)
NewY = OldY + DeltaXY * Cos(facing * bj_DEGTORAD)

Assuming you measure pitch from horizontal up, so 90 is up and -90 is down.