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
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top