HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Math Help.

08-17-2008, 10:38 PM#1
Gwypaas
I need help with creating a formula that does this:
I want to slide a unit with say 300 height down to 0 height ending on a specefic point.

An example is never wrong:
Unit A starts at 300 height position 20/40.
Now I want to slide Unit A down to Height 0 ending at position 60/70.

How would I do that?

And of course there's 1 problem, I can't store any more real values then the units position and flyheight + end the same.

Edit - The unit will slide through a timer with a constant speed.
08-17-2008, 10:43 PM#2
the-thingy
Over what period of time (or what speed per second)?
08-17-2008, 10:43 PM#3
Gwypaas
Yeah, I'll be using a timer so it will be like 10 pixels every interval.
08-17-2008, 10:52 PM#4
the-thingy
Hmm, did a few notes and this is what I got (not the best at math, but I think it's correct)

(The figures were only for helping me ^^)
Quote:
Speed - 800
Distance - 500
Start Height - 300
End height - 0
Time = Distance/Speed = 500/800 = 0.625 seconds

Height rate:
((Start Height - End Height)/Time)
((300-0)/0.625)
300/0.625
480



Height rate formula
((Start Height - End Height)/(Distance/Speed))
08-17-2008, 11:04 PM#5
Themerion
EDIT

If you only want to change fly height...

Trigger:
Set SlidingUnit = (Use whatever unit you want)
Set NewHeight = 0
Set Speed = 150
Custom Script: call SetUnitFlyHeight(udg_SlidingUnit, udg_NewHeight, udg_Speed)

You can of course use the values directly:
Collapse JASS:
call SetUnitFlyHeight(udg_SlidingUnit, 0, 150)
08-17-2008, 11:10 PM#6
Gwypaas
I do know that, I mean, Cos and Sin values and such.

All I have is the unit and the fly height and where it should end and the fly heigt there.
08-17-2008, 11:19 PM#7
Themerion
You mean that the height change is not linear, but should use a Cos/Sin function to get a smoother look?
08-18-2008, 07:26 AM#8
Gwypaas
The thing is this:

I create the unit at a specefic point and then I want to slide that unit to another point. But the problem is this: The heights are different so I need to make it change height on a linear path.

But I'm not good enough in Math to find the right formulas for all the values.
08-18-2008, 07:39 AM#9
Strilanc
Code:
//axis distances
dx = x distance from position to target
same for dx, dz

//axis speeds
t = total time to complete slide
vx = dx / t
same for vy, vz

// ... when updating position ...
dt = timer period
new_x = old_x + vx*dt
same for new_y, new_z
08-18-2008, 02:49 PM#10
Gwypaas
But what if I don't want to have a specefic amount of time it slides on?
08-18-2008, 03:07 PM#11
Themerion
Quote:
All I have is the unit and the fly height and where it should end and the fly heigt there.

Yeah, but that leaves speed / duration variable. You can do it at any speed or any duration. You need a speed or a duration.
08-19-2008, 03:39 AM#12
Here-b-Trollz
Code:
H = Total height traversed
T = Time taken to move (in seconds)
P = Timer Interval (.02-.04 probably)
Zm = Z change per timer interval

set Zm = H/T*P