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: 259

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

      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