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

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
hey.. i really dont like all those systems of jumping out-there..
so i tried to make my own, for some reason, nothing happends..
and the unit just stays there.

JASS:
library JumpEngine initializer OnInit
    
    globals
        private constant        real                GravityForce        = 0.75
        private                 unit array          GravityUnit
        private                 integer array       GravityCount
        private                 real array          GravityStart
        private                 boolean array       GravityJumpPlus
    endglobals
    
    private function SetHeightPlus takes unit u returns nothing
        call SetUnitFlyHeight(u, (GetUnitFlyHeight(u) + GravityForce), 0)
    endfunction
    
    private function SetHeightMinus takes unit u returns nothing
        call SetUnitFlyHeight(u, (GetUnitFlyHeight(u) - GravityForce), 0)
    endfunction
    
    function SetJumper takes integer i, unit n returns nothing
        set GravityUnit[i] = n
    endfunction
    
    function GetJumper takes integer i returns unit
        return GravityUnit[i]
    endfunction
    
    private function ClearJump takes integer i returns nothing
        set GravityUnit[i] = null
        set GravityStart[i] = 0
        set GravityJumpPlus[i] = false
        set GravityCount[2] = GravityCount[2] - 1
            if GravityCount[2] == 0 then
                set GravityCount[1] = 0
            endif
    endfunction
    
    function ForceStop takes nothing returns nothing
        set GravityCount[1] = 0
        set GravityCount[2] = 0
        set GravityCount[3] = 0
    endfunction
    
    private function OnLoop takes nothing returns nothing
        local real h = 0
        if GravityCount[1] >= 1 then
            loop
                if GravityCount[3] == GravityCount[1] then
                    set GravityCount[3] = 1
                else
                    set GravityCount[3] = GravityCount[3] + 1
                endif
                    if GravityUnit[GravityCount[3]] != null then
                        if GravityJumpPlus[GravityCount[3]] == true then
                            if GetUnitFlyHeight(GravityUnit[GravityCount[3]]) >= 10 then
                                call SetHeightMinus(GravityUnit[GravityCount[3]])
                            else
                                call ClearJump(GravityCount[3])
                            endif
                        else
                            if GetUnitFlyHeight(GravityUnit[GravityCount[3]]) < GravityStart[GravityCount[3]] then
                                call SetHeightPlus(GravityUnit[GravityCount[3]])
                            else
                                set GravityJumpPlus[GravityCount[3]] = true
                            endif
                        endif
                    endif
            endloop
        endif
    endfunction
    
    function Jump takes unit u, real startheight returns nothing
        set GravityCount[1] = GravityCount[1] + 1
        set GravityCount[2] = GravityCount[2] + 1
        set GravityUnit[GravityCount[1]] = u
        set GravityStart[GravityCount[1]] = startheight
    endfunction
    
    private function OnInit takes nothing returns nothing
        call TimerStart(CreateTimer(), 0.032, true, function OnLoop)
    endfunction
endlibrary



  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set u = Blood Mage 0001 <gen>
      • Set r = 750.00
      • Custom script: call Jump(udg_u, udg_r)


thanks in advance.
 
Level 9
Joined
May 27, 2006
Messages
498
Add Crow Form to the unit (and then remove the ability) before changing its' flying height. Should work.

The only problem is, this will make the game consider the unit as a flying unit (allowing it to fly over obstacles, etc). And I'm not sure whether you can change units' movement type back to ground.
 
Level 11
Joined
Sep 12, 2008
Messages
657
well.. im so stupid i forgot that >.>
i didnt use height a long time now..
thanks =] +rep

Edit: any 1 can tell me how do i get distance from 2 points?
since im trying to do a rush forward kind of skill,
so instead of another crazy loop, im trying to use a knockback system that basicly gets the hero to go forward instead.
this is a unit target spell, so it cant just get any duration depending on skill,
how can i know the duration the knockback should go thru? ;/
i use this knockback system:

http://www.hiveworkshop.com/forums/jass-functions-413/knockback-unit-35545/
 
Last edited:
You need distance/max distance. For example, if the max distance you can travel is 800 and the distance between your unit and the target is 600, the duration would be 800/600 = 1.33. Max Distance is the ability's field: Stats - Cast Range.
So, you can start a timer to expire after 1.33 seconds or periodically count the distance between your unit and the target, so that, if it is lower than 128, stop the effect.
 
Level 11
Joined
Sep 12, 2008
Messages
657
oh.. and i dont use a timer, i use a made knockback system.. since im too lazy.

so this is how:

JASS:
local real MaxDistance = 800
local real DistanceFromEnemy = DistanceBetweenPoints(Location(GetUnitX(caster), GetUnitY(caster)), Location(GetUnitX(target), GetUnitY(target))
local real Duration = MaxDistance/DistanceFromEnemy
is that correct?
 
JASS:
local real DistanceFromEnemy = DistanceBetweenPoints(Location(GetUnitX(caster), GetUnitY(caster)), Location(GetUnitX(target), GetUnitY(target))
Leaks twice; "Location()" function creates a new location.
Better use:
JASS:
local real array r
set r[0] = 800
set r[1] = GetUnitX (caster)
set r[2] = GetUnitY (caster)
set r[3] = GetUnitX (target)
set r[4] = GetUnitY (target)
set r[5] = r[3] - r[1]
set r[6] = r[4] - r[2]
set r[7] = SquareRoot (r[5]*r[5] + r[6] * r[6])
set r[8] = r[7] / r[0]
I made a mistake before; it should be Distance/MaxDistance, I now made a couple of calculations, so the higher the Distance value (r[7]), the greater the duration (r[8]).
 
Level 11
Joined
Sep 12, 2008
Messages
657
well i knew it leaked, it was just to show if i understended ;p
and well.. it did fail =]
if it was far from enemy, it went close to him and worked,
if it was close from enemy, it went too far behing him.

well, this failed:

JASS:
local unit u = GetTriggerUnit()
        local unit t = GetSpellTargetUnit()
        local real ang = Atan2(GetUnitY(t)-GetUnitY(u), GetUnitX(t)-GetUnitX(u))
        local real dx = GetUnitX(t) - GetUnitX(u)
        local real dy = GetUnitY(t) - GetUnitY(u)
        local real dist = SquareRoot(dx * dx + dy * dy)
        local real dis = PerLevel_Distance * (GetUnitAbilityLevel(u, 'A002'))
        local real dur = 600/dist
        call Knockback(u, dis, ang, dur)

any idea? ;/
 
Well, the tutorial says that your ang parameter should be multiplied by * bj_DEGTORAD
Silvenon said:
If you by any chance have angle in degrees and want to use it for this function, when calling the function just multiply that angle with bj_DEGTORAD, example:

JASS:
call Knockback(u, d, a * bj_DEGTORAD, w)

I am not sure how does it take the parameters, for example why it needs duration AND distance, since the system could automatically do it, but I guess that, if the rad conversion doesn't work, it must be something with the parameters.
 
well i knew it leaked, it was just to show if i understended ;p
and well.. it did fail =]
if it was far from enemy, it went close to him and worked,
if it was close from enemy, it went too far behing him.

well, this failed:

JASS:
local unit u = GetTriggerUnit()
        local unit t = GetSpellTargetUnit()
        local real ang = Atan2(GetUnitY(t)-GetUnitY(u), GetUnitX(t)-GetUnitX(u))
        local real dx = GetUnitX(t) - GetUnitX(u)
        local real dy = GetUnitY(t) - GetUnitY(u)
        local real dist = SquareRoot(dx * dx + dy * dy)
        local real dis = PerLevel_Distance * (GetUnitAbilityLevel(u, 'A002'))
        local real dur = 600/dist
        call Knockback(u, dis, ang, dur)

any idea? ;/

I think arctan2 uses (x,y) not (y,x)...

and maybe this
call Knockback(u, dis, ang, dur)

should be

call Knockback(u, dist, ang, dur) so that it will only land on the unit's position...
 
Level 11
Joined
Sep 12, 2008
Messages
657
dude, how can i find time, if i dont know it? ;p
and i dont think bj_DEGTORAD is the problem,
i've been using hes system quite alot now, never occured that problem.. (your option just moves forward, but if its away from enemy, it gets to him, if im close to enemy, it goes past him.

edit: hmm.. bj_DEGTORAD is defintly not the problem, i've tried with it and..
my hero just went right o.o
 
Level 9
Joined
May 27, 2006
Messages
498
JASS:
local real dur = 600/dist
I'm fairly sure that this should've been the other way around; local real dur = dist/600
Since time = distance / speed, not speed / distance. (miles/km per hour, for example)
Also, as far as i understand, dis is the value that determines how fast the unit moves. Therefore it should be local real dur = dist/dis
 
Level 11
Joined
Sep 12, 2008
Messages
657
That actually makes sense.. lemme try it and edit =]

edit: this went too far.

JASS:
        local unit u = GetTriggerUnit()
        local unit t = GetSpellTargetUnit()
        local real ang = Atan2(GetUnitY(t)-GetUnitY(u), GetUnitX(t)-GetUnitX(u))
        local real dis = PerLevel_Distance * (GetUnitAbilityLevel(u, 'A002') * PerLevel_MultiplyDistance)
        local real dx = GetUnitX(u) - GetUnitX(t)
        local real dy = GetUnitY(u) - GetUnitY(t)
        local real dist = SquareRoot(dx * dx + dy * dy)
        local real dur =  dist/dis
        call Knockback(u, dis, ang, dur)
 
dude, how can i find time, if i dont know it?

distance / speed = time

and if you can't take it make your own function

the author of the knockbacksystem added lots of documentation
he even wrote a list of what each parameter does

it will move dis 1/0.035 times per second btw

look at the code and you will see this
JASS:
function Knockback takes unit u, real d, real a, real w returns nothing
    call Data.create(u, R2I(w / Interval()), d, a, 0, 0, "", "")
endfunction
just reverse the equatation
 
Status
Not open for further replies.
Top