• 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.

Jump Spell, Math

Status
Not open for further replies.
Level 13
Joined
Mar 16, 2008
Messages
941
Hi there.
First of all, no I don't want to annoy you with a "need jum spell plsssss" request :wink: I have my spell already finished, but while thinking a bit (and watching that weird spell) I saw that I made a triangle, sure there is no other possibility with my calculations.
I just wanted to ask for a formula for the height.

-a*(x-d/2)²+h

I would do it like this, with 'd' as distance and 'h' as maximumheight the parable will go through the position of the caster and the target, but just if 'a' has the right value.

My problem is to define 'a' in dependence on 'd' and 'h' :confused:

I hope you can help me, or at least understand the text :ugly:

Greets, Justify
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Well it depends what you want.

If you want it to be based on height/distance/time, I think the best is in a thread started by me called Parabula (or something like that) in the Jass forum.

Anyway, if you need this just for your own map, you can just use the easiest way and use a value that decreases its value, kinda like a knockback function just that here it goes beneath zero.
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
Here's a physics formula that could help you with what you need:

∆s = 1/2*a*∆t^2 + vi*∆t

Where ∆s is the position vector.
∆t is the variation in time.
a is the constant of gravitational acceleration ( -9.81 m/s^2)
vi is the initial speed.

So let's say you'd launch something at 20 m/s in the air, here's what your formula would look like:

∆s = -4.905*∆t^2 + 20*∆t

We could isolate ∆t just for the heck of it, to find when it would collide with the ground:

f(x) = ax^2 + bx + c
0 = -4.905*∆t^2 + 20*∆t
∆t = (-b+-sqrt(b^2-4ac))/2a
∆t = (-20 +- sqrt(400))/-9.81
∆t= 4.077471967 seconds

So the object would collide with the ground (height 0) after about 4 seconds. Of course, this also works with horizontal launches. All you have to consider, though, is the vertical launch speed. Note also that this doesn't take account of air drag or resistance or things like that, only in a theoretical system.

Physics is fun!!
 
Level 13
Joined
Mar 16, 2008
Messages
941
Okay, I searched for your Parabula thread wolf and what I found was this
(in the same thread just some posts behind you). I just tried it and it works perfectly, or at least it is a nice smooth jump in my eyes.

But since I use it my hero just move to the right, as if the y coordinates weren't set but I don't know why :thumbs_down:
After some tests I can say:
The y coordinate is increased by 0.004 per call.
The x coordinate is increased by the distance to the target.

Okay its the angle, angle * bj_DEGTORAD is nearly 0, doesn't mather wich angle I realy have, why o_O
Okay i made some tests, I have to multiplicate it with 3600 to be the right angle, don't know why (the origninal blizz function works but without *3600) but it works, jump finish woho :D
JASS:
function Parabula takes real H, real T, real x returns real
    return ((4*H)/-(T*T))*(x*x) + ((4*H)/T)*x
endfunction

function Jump_High takes nothing returns real
    return 500.0
endfunction


function Jump_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction


function Jump_Move_Up takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit caster = GetHandleUnit(t, "caster")
    
    local integer loopindex = GetHandleInt(t, "highindex") + 1

    local real cz = GetUnitZ(caster)
    local real z = Parabula(Jump_High(), 0.98, I2R(loopindex)/28.0)
    
    call SetUnitZ(caster, z)
    
    if (loopindex >= 28) then
        call PauseTimer(t)
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        set t = null
    else
        call SetHandleInt(t, "highindex", loopindex)
    endif
endfunction

function Jump_Move_Forward takes nothing returns nothing
    local timer tforward = GetExpiredTimer()
    
    local unit caster = GetHandleUnit(tforward, "caster")
    
    local real range = GetHandleReal(tforward, "range")
    local real angle = GetHandleReal(tforward, "angle")
    local real cx = GetUnitX(caster)
    local real cy = GetUnitY(caster)
    local real xforward = cx + (range / 28) * Cos(angle * bj_DEGTORAD)
    local real yforward = cy + (range / 28) * Sin(angle * bj_DEGTORAD)
    
    local integer loopindex = GetHandleInt(tforward, "forwardindex")
    
    call SetUnitX(caster, xforward)
    call SetUnitY(caster, yforward)

    set loopindex = loopindex + 1
    
    if (loopindex >= 28) then
        call PauseTimer(tforward)
        call FlushHandleLocals(tforward)
        call DestroyTimer(tforward)
        set tforward = null
    else
        call SetHandleInt(tforward, "forwardindex", loopindex)
    endif
endfunction

function Jump_Actions takes nothing returns nothing
    local timer tup = CreateTimer()
    local timer tforward = CreateTimer()
    
    local unit caster = GetSpellAbilityUnit()
    local unit target = GetSpellTargetUnit()
    local real cx = GetUnitX(caster)
    local real cy = GetUnitY(caster)
    local real tx = GetUnitX(target)
    local real ty = GetUnitY(target)
    
    local real dx = tx - cx
    local real dy = ty - cy
    local real range = SquareRoot(dx*dx + dy*dy)
    local real angle = Atan2(dy,dx) * bj_DEGTORAD * 3600

    call SetHandleHandle(tup, "caster", caster)
    call TimerStart(tup, 0.035, true, function Jump_Move_Up)
    
    call SetHandleHandle(tforward, "caster", caster)
    call SetHandleReal(tforward, "range", range)
    call SetHandleReal(tforward, "angle", angle)
    call TimerStart(tforward, 0.035, true, function Jump_Move_Forward)
endfunction

// ==================================================
function InitTrig_Jump takes nothing returns nothing
    set gg_trg_Jump = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Jump, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Jump, Condition( function Jump_Conditions ) )
    call TriggerAddAction( gg_trg_Jump, function Jump_Actions )
endfunction

Hope you see whats wrong :>

Greets, Justify

Btw: Hindy, nice idea, but not if you know the fact that my unit will jump for 1 second (0.98 exactly) :grin:
And, physics suck :razz: Don't ask me why, I love maths but I hate physics, weird combination but thats me :razz:
 
Last edited:
Level 12
Joined
Aug 20, 2007
Messages
866
Um

I made a grenade spell map recently, I had algebraically separated each piece, I know the resource had been ignored (now that I look back on it, no wonder) but somebody told me it helped them make some sense of the parabola formulas


EDIT


You could probably do a system with air drag/resistance without much difficulty, just gotta do a little bit more calculating
I don't see what the big deal is with people who hate physics or math, I mean for chrissake you've got paper to record the stuff your putting down
 
Status
Not open for further replies.
Top