Problem with jump system

TheLegend

New Member
Reaction score
10
im having some problems with a jump system im making, well that is, only one problem. When the system starts the unit does change heights and it does move with the key system but the height gets set to 0 each 3rd run and it kinda bounces the unit
JASS:
library jumpenhanced initializer jumpinit uses OZSYS
    globals
        private boolean array LEFT_PRESSED            //Monitors if the Left key is pressed
        private boolean array RIGHT_PRESSED           //Monitors if the Right key is pressed
        private boolean array UP_PRESSED              //Monitors if the Up key is pressed
        private boolean array DOWN_PRESSED            //Monitors if the Down key is pressed
        private integer totaldata = 0                 //The total ammount of jumping units
        private real array xadjust                    //Loc x offset for moving the unit
        private group jumpers = CreateGroup()         //Units jumping
        private real array yadjust                    //Loc y offset for moving the unit
    endglobals
    private struct storeddata
        unit u                                   //the unit jumping
        location startloc                        //the units start location
        integer playerid                         //id of the units owner
        real maxheight                           //the jumps max height
        real nowheight                           //the jumps height now
        real newflyheight                        //fly height that has to be set to simulate flight
        location currentloc                      //current location of the unit
        integer reachedmax                       //+8 if not -8 if it did, will adjust the height
    endstruct
    globals
        private storeddata array D               //jump data array
    endglobals
    //These functions set the offsets for moving the unit by pressing keys
    //--------------------------------------------------------------------
    private function ARROW_LEFT takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        if LEFT_PRESSED<i> then
            set LEFT_PRESSED<i> = false
            set xadjust<i> = xadjust<i> + 8
        else
            set LEFT_PRESSED<i> = true
            set xadjust<i> = xadjust<i> - 8
        endif
    endfunction
    private function ARROW_RIGHT takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        if RIGHT_PRESSED<i> then
            set RIGHT_PRESSED<i> = false
            set xadjust<i> = xadjust<i> - 8
        else
            set RIGHT_PRESSED<i> = true
            set xadjust<i> = xadjust<i> + 8
        endif
    endfunction
    private function ARROW_UP takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        if UP_PRESSED<i> then
            set UP_PRESSED<i> = false
            set yadjust<i> = yadjust<i> - 8
        else
            set UP_PRESSED<i> = true
            set yadjust<i> = yadjust<i> + 8
        endif
    endfunction
    private function ARROW_DOWN takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        if DOWN_PRESSED<i> then
            set DOWN_PRESSED<i> = false
            set yadjust<i> = yadjust<i> + 8
        else
            set DOWN_PRESSED<i> = true
            set yadjust<i> = yadjust<i> - 8
        endif
    endfunction
    //--------------------------------------------------------------------
    private function destroyD takes integer id returns nothing
        local storeddata data = D[id]
        call SetUnitPathing(data.u, true )
        set data.u = null
        set data.reachedmax = 0
        set data.playerid = 0
        set data.maxheight = 0
        set data.nowheight = 0
        set data.newflyheight = 0
        set data.startloc = null
        set data.currentloc = null
        // The loop will correct the array, that is it 
        //will remove the gap created by the deleted data
        loop
            set D[id] = D[id + 1]
            set id = id + 1
            exitwhen id == totaldata
        endloop
        call data.destroy()
        set totaldata = totaldata - 1
    endfunction
    //This function will identificate the data which is connected to the unit
    private function identify takes unit u returns integer
        local integer unitid = 0
            loop
                set unitid = unitid + 1
                exitwhen unitid == totaldata
            endloop
        return unitid
    endfunction
    private function unitadjust takes nothing returns nothing
        local integer id = identify(GetEnumUnit())      //Locate the data for the unit
        local location newloc
        set D[id].currentloc = GetUnitLoc(D[id].u)      //Set the units location now
        if D[id].nowheight &gt; D[id].maxheight then       //Checks if the unit reached max
            set D[id].reachedmax = -8
        endif
        set D[id].nowheight = D[id].nowheight + D[id].reachedmax  //adjust the current height of the unit
        set D[id].newflyheight = D[id].nowheight - GetLocationZ(D[id].currentloc) //sets the flight height
        if D[id].newflyheight &lt; 1 then
            set D[id].newflyheight = 1
        endif
        call SetUnitFlyHeight(D[id].u,D[id].newflyheight,0)
        // this will move the unit to the adjsuted loc
        if xadjust[D[id].playerid] != 0 or yadjust[D[id].playerid] != 0 then
            //call IssueImmediateOrder(D[id].u,&quot;stop&quot;)
            set newloc = Location(GetLocationX(D[id].currentloc) + xadjust[D[id].playerid],GetLocationY(D[id].currentloc) + yadjust[D[id].playerid])
            //call IssuePointOrderLoc(D[id].u,&quot;move&quot;,D[id].currentloc)
            call SetUnitPositionLoc(D[id].u, newloc)
            call SetUnitFacing(D[id].u, AngleBetweenPoints(D[id].currentloc, newloc))
        endif
        call RemoveLocation(newloc)
        if 2*D[id].newflyheight + GetUnitPointValue(D[id].u) - OZSYS_GetMinimumZ(D[id].currentloc,false,16,true)&lt; 0 then
            call GroupRemoveUnit(jumpers,D[id].u)
            call destroyD(id)
        endif
    endfunction
    public function jump takes unit u, real jumpheight returns nothing
        local storeddata data = storeddata.create()
        if IsUnitInGroup(u,jumpers) == false then
            call SetUnitPathing(u, false )
            call UnitAddAbility(u, &#039;Amrf&#039;)
            call UnitRemoveAbility(u, &#039;Amrf&#039;)
            call GroupAddUnit(jumpers,u)
            set totaldata = totaldata + 1
            set data.u = u
            set data.playerid = GetPlayerId(GetOwningPlayer(u))
            call SetCameraTargetController(u, 0, 0, false)
            set data.startloc = GetUnitLoc(u)
            set data.currentloc = GetUnitLoc(u)
            set data.reachedmax = 8
            set data.maxheight = GetLocationZ(data.startloc) + GetUnitFlyHeight(u) + jumpheight
            set D[totaldata] = data
        endif
    endfunction
    private function jumpadjust takes nothing returns nothing
        call ForGroup(jumpers,function unitadjust)
    endfunction
    private function jumpinit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local trigger t1 = CreateTrigger()
        local trigger t2 = CreateTrigger()
        local trigger t3 = CreateTrigger()
        local trigger t4 = CreateTrigger()
        local integer i = 0
        loop
            call TriggerRegisterPlayerEvent(t1, Player(i), EVENT_PLAYER_ARROW_LEFT_DOWN)
            call TriggerRegisterPlayerEvent(t1, Player(i), EVENT_PLAYER_ARROW_LEFT_UP)
            call TriggerRegisterPlayerEvent(t2, Player(i), EVENT_PLAYER_ARROW_RIGHT_DOWN)
            call TriggerRegisterPlayerEvent(t2, Player(i), EVENT_PLAYER_ARROW_RIGHT_UP)
            call TriggerRegisterPlayerEvent(t3, Player(i), EVENT_PLAYER_ARROW_UP_DOWN)
            call TriggerRegisterPlayerEvent(t3, Player(i), EVENT_PLAYER_ARROW_UP_UP)
            call TriggerRegisterPlayerEvent(t4, Player(i), EVENT_PLAYER_ARROW_DOWN_DOWN)
            call TriggerRegisterPlayerEvent(t4, Player(i), EVENT_PLAYER_ARROW_DOWN_UP)
            set LEFT_PRESSED<i> = false
            set RIGHT_PRESSED<i> = false
            set UP_PRESSED<i> = false
            set DOWN_PRESSED<i> = false
            set xadjust<i> = 0
            set yadjust<i> = 0
            set i = i + 1
            exitwhen i == bj_MAX_PLAYERS
        endloop
        call TriggerAddAction(t1,function ARROW_LEFT)
        call TriggerAddAction(t2,function ARROW_RIGHT)
        call TriggerAddAction(t3,function ARROW_UP)
        call TriggerAddAction(t4,function ARROW_DOWN)
        call TriggerRegisterTimerEvent(t,0.03,true)
        call TriggerAddAction(t,function jumpadjust)
        set i = 0
        set t1 = null
        set t2 = null
        set t3 = null
        set t4 = null
    endfunction
endlibrary
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
Firstly, you don't simulate a jump. It should be based on a x-x^2 type function to be a jump (Plot to see how it is).
Secondly your actions give no logic sense at first glance or maybe second, you must simplify your code.
Removing by location's height makes you "walk" on 2nd cliff height and above.
And you order unit to move instead of changing his position, ordering a unit every 0.03 seconds restarts unit animation (ugly) and maybe stops it while he changes from defense to move action.
To make it right, just calculate how much you want your unit to move per second and what distance. You need better maths to solve these problems. I could tell you to look my system, but....uhm well, it may not help you if you don't understand where to look.
 

TheLegend

New Member
Reaction score
10
It should be based on a x-x^2 type function to be a jump
i'm not simulating parabolic movement, in this system you use keys to move
ordering a unit every 0.03 seconds restarts unit animation (ugly)
the unit walks perfectly, without lagging or anything, there still is a small problem when you hit an unpathable loc, if your height isnt higher than the loc's you get stuck, unable to move while you jump, only right click movement works
You need better maths to solve these problems
was first in the state in maths ;) the problem is only that the fly height gets set to 0 each 3rd loop but it continues normally, as if the editor cant read some height so he replaces it with 0.
Ill improve my coding and add some comments for easy understanding
 

TheLegend

New Member
Reaction score
10
is this better, i updated the post... now tell me how to fix the damn Fly Height bug
 

TheLegend

New Member
Reaction score
10
just one thing
JASS:
        if 2*D[id].newflyheight + GetUnitPointValue(D[id].u) - OZSYS_GetMinimumZ(D[id].currentloc,false,16,true)&lt; 0 then
            call GroupRemoveUnit(jumpers,D[id].u)
            call destroyD(id)
        endif

should be replaced with this
JASS:
        if D[id].newflyheight &lt; 0 then
            call GroupRemoveUnit(jumpers,D[id].u)
            call destroyD(id)
        endif
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
I did it before you post, I tried my best, and only thing i did is to add 3 units for red player and move them 1 by 1, not simultaneously :(
please try simple linked list, it will save you for good.
 

TheLegend

New Member
Reaction score
10
do you know any jump system that is designed to be keyboard controlled like the one im trying to make, pls post here if you do. The only ones i can find are the classic parabolic movement jump systems. This system is just a subsystem of my new creation the VPS (vertical pathing system) and i know that VPS works but i wanted to increase its use by adding a jump system next to the bridge system i made
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top