Snippet Jump

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Jump

JASS:
//////////////////////////////////////////////////////////////////////////////////////////////
//      _______    _    _     _________    ____
//     |__   __|  | |  | |   |  _   _  |  | __ |   by
//        | |     | |  | |   | | | | | |  | ~__|   kingking
//       _| |     | |__| |   | | | | | |  | |
//      |___|     |______|   |_| |_| |_|  |_|      v1.01
//
//      
//      What is Jump?
//      This library makes jumping more natural. =D
//      
//      ==How to use== o.o?
//      call Jump_Start(whichunit,speed)
//      
//      Extra :
//      TriggerRegisterUnitLanded(whichtrigger)
//      GetLandedUnit() -> landed unit
//
//      Requires :
//      T32
//      Event
//      Jass helper 0.9.K.0 or newer
//      Jump Ability(Get from Object editor)
//      Fly Trick(Get from Object editor)
//
//      Impletement note :
//      Ensure the rawcodes in library are correct.
//      "Data - Spell List" in Jump Ability must includes Fly Trick.
//////////////////////////////////////////////////////////////////////////////////////////////


JASS:
library Jump initializer Init requires T32, Event

    globals
        //Configurable.
        private constant integer JUMP_ABILITY = 'A001'
        private constant integer FLY_TRICK = 'Arav'// 'Amrf' does same
        public constant real GRAVITIONAL_ACCELERATION = 30.
    endglobals
    
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Restricted Area~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    globals
        private unit Landed_Unit = null
        private integer UnitLandedEvent
        private constant real PeriodicGA = GRAVITIONAL_ACCELERATION / T32_FPS
    endglobals
    
    private struct Jump
        unit targ
        real speed
        real height
        integer status
        integer ticks
        integer add
        
        private method periodic takes nothing returns boolean
            if .speed > 0. and .status == 1 then
                set .ticks = .ticks + 1
                set .speed = .speed - PeriodicGA
                set .height = .height + .speed
                call SetUnitFlyHeight(.targ,.height,0.)
                if .speed < .0 then
                    set .status = 2
                    set .speed = .001
                endif
            endif
            if .speed > 0. and .status == 2 and .ticks > 0 then
                set .ticks = .ticks - 1
                set .speed = .speed + PeriodicGA
                set .height = .height - this.speed
                call SetUnitFlyHeight(.targ,.height,0.)
            endif
            if .ticks > 0 then
                return false
            endif
            call .destroy()
            return true
        endmethod
        
        private method onDestroy takes nothing returns nothing
            if .add == 1 then
                call UnitRemoveAbility(.targ,JUMP_ABILITY)
            endif
            set .ticks  = 0
            set .speed = 0.
            set .height = 0.
            set .status = 0
            set Landed_Unit = .targ
            call FireEvent(UnitLandedEvent)
        endmethod
        
        implement T32
        
    endstruct
    
    public function Start takes unit whichunit, real speed returns nothing
        local Jump d = Jump.create()
        set d.targ = whichunit
        set d.speed = speed / T32_FPS
        set d.status = 1 //1 -> up, 2->down
        set d.height = GetUnitDefaultFlyHeight(d.targ)
        if UnitAddAbility(d.targ,JUMP_ABILITY) then
            set d.add = 1
        else
            set d.add = 2
        endif
        call d.startPeriodic()
    endfunction
    
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Trigger~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        
    function GetLandedUnit takes nothing returns unit
        return Landed_Unit
    endfunction
    
    function TriggerRegisterUnitLanded takes trigger whichtrigger returns EventReg
        return TriggerRegisterEvent(whichtrigger,UnitLandedEvent)
    endfunction
    
    private function Init takes nothing returns nothing
        local integer i = 0
        loop
        exitwhen i > 15
            call SetPlayerAbilityAvailable(Player(i),JUMP_ABILITY,false)
            set i = i + 1
        endloop
        set UnitLandedEvent = CreateEvent()
    endfunction
    
endlibrary
 

Attachments

  • Jump.w3x
    37 KB · Views: 260

uberfoop

~=Admiral Stukov=~
Reaction score
177
Only allows for 1 gravitational accelleration value?

A good jump function should allow you to, with a fair amount of ease, control duration and maximum height. In fact, since that requires two inputs anyway, you might as well make it those two, rather than an 'initial speed' value which nobody wants to calculate and makes it annoying to manipulate.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Make an OnUnitLands Event. :thup: :thup:
JASS:
                call UnitAddAbility(.targ,FLY_TRICK) // What if the unit legitimately has the ability?
                call UnitRemoveAbility(.targ,FLY_TRICK)

-->
JASS:
                if UnitAddAbility(.targ,FLY_TRICK) then
                    call UnitRemoveAbility(.targ,FLY_TRICK)
                endif

Also, this should not be in the periodic method it should be on start - and using "if UnitAddAbility then" MAY break condition threads - please test. :)
 

Nestharus

o-o
Reaction score
84
Add this stuff in-

1. Weight for objects

2. Gravity based on areas and a global default gravity (rectwraps?)

3. Force (this may come from a unit attribute or it may come from the ability, who knows, let people input it themselves)

4. Jump Angle? (maximum jump distance would be at a 45 degree angle, but what if people wanted to jump high for some reason? Let them manipulate the angle).

And well, that's all I can think of for now ^_^.

From there determine the parabolic arc based on the gravity, the force, and the angle.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>1. Weight for objects
No. Anyone with basic physics knowledge knows weight doesn't effect gravity.

>2. Gravity based on areas and a global default gravity (rectwraps?)
Maybe. Gravity modifier rects could be cool. :D

>3. Force (this may come from a unit attribute or it may come from the ability, who knows, let people input it themselves)
Bleh. Users can do this themselves. Simple interfaces - else be ware.

>4. Jump Angle? (maximum jump distance would be at a 45 degree angle, but what if people wanted to jump high for some reason? Let them manipulate the angle).
Shrug. :p
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
No. Anyone with basic physics knowledge knows weight doesn't effect gravity.
Lol, 9.81m/s.
 

Trollvottel

never aging title
Reaction score
262
No. Anyone with basic physics knowledge knows weight doesn't effect gravity.
Lol, 9.81m/s.

yes. for ALL masses 9.81.

functions like jump x wc3units/metres high are missing btw. not everyone wants to calculate it himself
(if you dont know it either, just set the equation

-1/2 * g * t² + v0 * t = wantedheight

and solve it to v0 so it is

v0 = (wantedheight + 1/2 * g * t²) / t
)
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
From what I see there will be problems when jumping from a higher ground to a lower one since you don't do anything with GetLocationZ() etc.
Test it, you won't be land at your targeted location (if it is a targeting spell).

Edit:
Okay so it doesn't seem to be a used in targeting skills and such. You just adjust the height? It may be useful but I call it very, very simple. And you should at least use the physic formula Trollvottel mentioned already so it looks much more realistic.
By the way there should be more constants/arguments that can be changed by the user.
 

Nestharus

o-o
Reaction score
84
>1. Weight for objects
No. Anyone with basic physics knowledge knows weight doesn't effect gravity.

Actually, I was thinking of impact, I included the weight in the specific parabolic arc as a typo ><.

yes. for ALL masses 9.81.

That is actually based on gravity : \. Also, that statement for the planet is untrue anyways because gravity isn't a constant around the world, but I'm probably just nitpicking at this point : ).

That's why I suggested gravity for various areas =p.

And if you really want to get gravity, you should determine the size of the planet and the interaction between each object =). We all have our own gravity after all : P. You should also take into account rotational speed. And maybe rather than gravity for various areas, allow users to determine density. That'll make it as realistic as possible =P.

Also, you could have gravity modifiers I guess =), stuff that offsets the gravity of a region or overwrites it =P.
 

Romek

Super Moderator
Reaction score
964
This is Warcraft; nearly everything that has been suggested is just overkill.

Anyway, we've already got numerous jumps/jump templates, etc on this site.
This one does nothing special, and doesn't even compare to some of the better ones here.

Graveyarded.
 

Jesus4Lyf

Good Idea™
Reaction score
397
That is actually based on gravity : \. Also, that statement for the planet is untrue anyways because gravity isn't a constant around the world, but I'm probably just nitpicking at this point : ).

That's why I suggested gravity for various areas =p.

And if you really want to get gravity, you should determine the size of the planet and the interaction between each object =). We all have our own gravity after all : P. You should also take into account rotational speed. And maybe rather than gravity for various areas, allow users to determine density. That'll make it as realistic as possible =P.

Also, you could have gravity modifiers I guess =), stuff that offsets the gravity of a region or overwrites it =P.
Simplicity-520x396.jpg
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • 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 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