• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Jump / Arch formula

Status
Not open for further replies.
Level 18
Joined
Oct 18, 2007
Messages
930
Ok i kinda need a formula to make a unit arch/jump over a distance over a given time.

The variables/info you are given is:
  1. real D ( Distance )
  2. real A ( Arch )
  3. real T ( Time )

I think i need some sort of height increase/decrease formula but dunno realy :S

If you know anything then post below
 
Level 14
Joined
Nov 23, 2008
Messages
187
Taken from Parabolic Function - Wc3campaigns:

JASS:
function ParabolaZ takes real h, real d, real x returns real
  return (4 * h / d) * (d - x) * (x / d)
endfunction

This function takes as a parameters the distance that the parabolic movement should move (d) and the maximum height the projectile will flight (h).

So x is a value between 0 and d, and the function will return the height for that value.

- Distance is d in function;
- Arc is probably h (or some fraction of height and distance);
- Time is required for x increment value.

xIncrement is defined by formula Distance * TimerPeriod / Time.

How to use:

JASS:
globals
  constant real TIMER_PERIOD = .025
  // . . .
endglobals

// . . .

function OnTimer takes nothing returns nothing
  // . . .
  set currentPos = currentPos + xIncrement
  set currentZ = ParabolaZ(maxHeight, maxDist, currentPos)
  // change flying height and doing other stuff...
  // . . .
endfunction

function Actions takes nothing returns nothing
  set maxHeight = 200.
  set maxDist = 1000.
  set maxTime = 5.
  set xIncrement = maxDist * TIMER_PERIOD / maxTime
  // . . .
  call TimerStart(tm, TIMER_PERIOD, true, function OnTimer)
endfunction
 
Level 18
Joined
Oct 18, 2007
Messages
930
Taken from Parabolic Function - Wc3campaigns:

JASS:
function ParabolaZ takes real h, real d, real x returns real
  return (4 * h / d) * (d - x) * (x / d)
endfunction



- Distance is d in function;
- Arc is probably h (or some fraction of height and distance);
- Time is required for x increment value.

xIncrement is defined by formula Distance * TimerPeriod / Time.

How to use:

JASS:
globals
  constant real TIMER_PERIOD = .025
  // . . .
endglobals

// . . .

function OnTimer takes nothing returns nothing
  // . . .
  set currentPos = currentPos + xIncrement
  set currentZ = ParabolaZ(maxHeight, maxDist, currentPos)
  // change flying height and doing other stuff...
  // . . .
endfunction

function Actions takes nothing returns nothing
  set maxHeight = 200.
  set maxDist = 1000.
  set maxTime = 5.
  set xIncrement = maxDist * TIMER_PERIOD / maxTime
  // . . .
  call TimerStart(tm, TIMER_PERIOD, true, function OnTimer)
endfunction

:p i realy want to avoid using the Parabola func, it bugs sometimes
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
vz = (g*t) / 2 vz is the velocity on the z axis, g is gravity (9.81) and t is time.
If you want to add arc you could do a little twist like this: vz = ((g * a) * t) / 2

How to use:
JASS:
globals
    constant timer t = CreateTimer()
    constant real grav = 9.81
    constant real interval = 0.04
   
    unit u
    real vx
    real vy
    real vz
    real a
    real exec
    real ti
endglobals

function Jump_child takes nothing returns nothing
    local real x1 = GetUnitX(u)
    local real y1 = GetUnitY(u)
    local real z1 = GetUnitFlyHeight(u)
    local real x2 = x1 + vx
    local real y2 = y1 + vy
    local real z2 = z1 + vz
    call SetUnitX(u, x2)
    call SetUnitY(u, y2)
    call SetUnitFlyHeight(u, z2, 0)
    set vz = vz - ((g * a) / exec)
    set time = time - interval
    if time <= 0. then
        set u = null
        call PauseTimer(t)
   endif
endfunction

function Jump takes unit uni, real x1, real y1, real x2, real y2, real time, real arc returns nothing
    set u = uni
    set exec = time / interval
    set vx = (x1 - x2) / exec
    set vy = (y1 - y2) / exec
    set vz = ((g * arc) * t) / 2
    set a = arc
    set ti = time
    call UnitAddAbility(u, 'Amrf')
    call UnitRemoveAbility(u, 'Amrf')
    call TimerStart(t, interval, true, function Jump_child)
endfunction

This is just an example and I think it should work.
If I have any errors, please correct me.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Like I already told you in the previous thread:

v0 = (-0.5*a*t+(x - x0)/t)*FPS

v0 - initial velocity
a - acceleration (gravity in your case)
x - final position(maximum height in your case)
x0 - starting position (0 in your case)
t - time to complete the movement
FPS - FPS...

Once you have the initial velocity you just make the height change with it and reduce it every frame by the acceleration (I.E gravity).
 
Status
Not open for further replies.
Top