Jump Trigger Issue

cleeezzz

The Undead Ranger.
Reaction score
268
JASS:
library Jump initializer Init requires KT

globals
    private constant integer FLY_ID = 'Amrf'
    private location tp
endglobals

private struct JS
    unit ju
    real a
    real b
    real c
    real cx
    real lz
    real lx
    real ly
    real ex
    real ey
    real arch
    real angle
    real s
    method onDestroy takes nothing returns nothing
        call PauseUnit(.ju,false)
        call SetUnitPathing(.ju,true)
        call SetUnitFlyHeight(.ju,0.,0.)
        set .ju = null
    endmethod
endstruct

private function GetUnitZ takes unit u returns real
    call MoveLocation(tp, GetUnitX(u),GetUnitY(u))
    return GetUnitFlyHeight(u) + GetLocationZ(tp)   
endfunction

private function GetZ takes real x, real y returns real
    call MoveLocation(tp, x,y)
    return  GetLocationZ(tp)   
endfunction

private function SetUnitZ takes unit u, real z returns nothing
    local real rz
    call MoveLocation(tp,GetUnitX(u),GetUnitY(u))
    set rz = z-GetLocationZ(tp)
    call SetUnitFlyHeight(u,rz,0.)
endfunction

private function Motion takes nothing returns boolean
    local JS d = KT_GetData()
    local real x
    local real y
    local real z
    local real speed
    local real dist
    if UnitAlive(d.ju) == false then
        call d.destroy()
        return true
    endif
    set x = GetUnitX(d.ju)
    set y = GetUnitY(d.ju)
    set z = GetUnitZ(d.ju)
    set dist = SquareRoot((d.lx-x)*(d.lx-x) + (d.ly-y)*(d.ly-y))
    set d.cx = d.cx + dist
    set d.lx = x
    set d.ly = y
    set d.lz = z
    set speed = (d.s*Sin((90.-(Atan((d.a*2)*d.cx+d.b))*bj_RADTODEG)*bj_DEGTORAD))/Sin(90.*bj_DEGTORAD)
    set x = x+speed*Cos(d.angle)
    set y = y+speed*Sin(d.angle)
    call SetUnitX(d.ju,x)
    call SetUnitY(d.ju,y)
    set z = d.a*(Pow(d.cx,2)) + d.b*d.cx + d.c
    call SetUnitZ(d.ju,z)
    if z <= 0 then
        call d.destroy()
        return true
    endif
    return false
endfunction

function UnitJump takes unit u, real tarx, real tary, real arcZ, real speed returns nothing
    local JS d = JS.create()
    local real ux = GetUnitX(u)
    local real uy = GetUnitY(u)
    local real dist = SquareRoot((ux-tarx)*(ux-tarx)+(uy-tary)*(uy-tary))
    call UnitAddAbility(u,FLY_ID)
    call UnitRemoveAbility(u,FLY_ID)
    set d.ju = u
    set d.lx = ux
    set d.ly = uy
    set d.ex = tarx
    set d.ey = tary
    set d.cx = 0.
    set d.lz = GetUnitZ(u)
    set d.s = speed
    set d.arch = arcZ
    set d.angle = Atan2((tary-d.ly),(tarx-d.lx))
    call SetUnitFacing(u,d.angle*bj_RADTODEG)
    set d.c = d.lz
    set d.b = (-dist-SquareRoot(Pow(dist,2)+(-4*((-Pow(dist,2))/((d.arch-d.c)*4))*d.c)))/(2*((-Pow(dist,2))/((d.arch-d.c)*4)))
    set d.a = (-d.c-(dist*d.b))/Pow(dist,2)
    call SetUnitPathing(d.ju,false)
    call PauseUnit(d.ju,true)
    call KT_Add(function Motion, d, 0.03)
endfunction
    
private function Init takes nothing returns nothing
    set tp = Location(0.,0.)
endfunction
endlibrary


Does not work correctly when jumping to a cliff thats higher than original point. See video.
http://www.youtube.com/watch?v=aXqUeyptkyE
(Note: vid may still be processing)
As you can see, the unit slides to the edge of the cliff before jumping.. why?
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
I have no idea what sort of crazy math mistake would have to be made to get the error you got in that video, and I can only assume that your posted source code is different from what you were using when that video was made, because the posted code has a very different but still glaring height error.

Right now, it seems as though your curve always assumes that the final terrain height is 0, and thus dips into the ground at the end whenever the curve ends on high ground regardless of where it starts. In fact, at z levels a few hundred units up, the unit never even seems to leave the ground. At roughly 250, the unit starts out in a leap but hits ground glaringly too early.
Basically: I myself am not very experienced with interpolation, so I won't fix this myself, but go change your formula to account for the end height of the parabola, because right now your formula seems to just be assuming that it's 0.

Also:
[ljass]/Sin(90.*bj_DEGTORAD)[/ljass]
You mean 1? You could remove a division operation, a multiplication operation, a trigonometric function call, and half a line of code here and nothing would change at all.


Your code is also drastically overcomplicated for no reason at all. The whole thing where you have variable speed makes no sense. Unless you're accounting for air resistance, the speed along the x-y plane of a trajectorized object should be constant, and right now the speed of unit along the parabola just looks unnatural, because it is unnatural.
 

cleeezzz

The Undead Ranger.
Reaction score
268
>Basically: I myself am not very experienced with interpolation, so I won't fix this myself, but go change your formula to account for the end height of the parabola, because right now your formula seems to just be assuming that it's 0.

me neither, i know i spent a long time like half a year ago figuring this out but i forgot now.

>The whole thing where you have variable speed makes no sense.

Speed changes throughout the arc to keep a constant speed defined by d.s

It calculates the change in X to give the proper distance change to make the unit move the same speed throughout the arc (remember its also traveling in the Z dimension)

The divide by Sin(90) makes sense because that = 1, that was just the raw formula i got from the parabolic function when solving for speed
ill change that
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
It calculates the change in X to give the proper distance change to make the unit move the same speed throughout the arc (remember its also traveling in the Z dimension)
I figured that's what it might be attempting to account for, I just can't fathom why. Varying horizontal speed to keep constant unit speed throughout the arc makes no sense at all. It's mathematically messy, nonrepresentative of reality, strange on the eyes, and probably a significant part of what's messing up your library.
 

cleeezzz

The Undead Ranger.
Reaction score
268
lol dunno, i want it constant, its actually not the speed though, its my variables

d.a d.b d.c

they stand for the a b c in the quadratic function

ax^2 + bx + c

for some reason, they arent being set correctly when going uphill. trying to figure out why.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Regardless of any mathematical errors that may be occuring in your formulas, as I pointed out before, it's probably because you aren't accounting for landing height anywhere (You have a GetZ function, but it is never used).
 

cleeezzz

The Undead Ranger.
Reaction score
268
JASS:
    if z <= 0 and GetTerrainCliffLevel(GetUnitX(d.ju),GetUnitY(d.ju)) == GetTerrainCliffLevel(d.ex,d.ey) then
        call d.destroy()
        return true
    endif


found the error, for some reason, when you target a cliff thats above, the Z is negative which canceled the jump and it tried to keep jumping like that. So to fix it, i just added a check that the cliff level has to be the same level as the cliff level where the unit is supposed to end up (im only using this jump to cross cliffs anyway)

thanks, ill try to optimize the math too
 

Light Alkmst

New Member
Reaction score
20
even though it uses a location, try adding GetLocationZ() of your start point, and subtracting GetLocationZ() of your current point, to your height

EDIT: sorry. didn't notice "found the error" the first several times i read through. XD
 

cleeezzz

The Undead Ranger.
Reaction score
268
actually, the real problem was, i wasnt setting the arc height correctly when i was calling the function O_O.

but oh well. thanks
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top