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

      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