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

[vJASS] Parabola problem

Status
Not open for further replies.
Level 3
Joined
Mar 14, 2011
Messages
32
Hello! ive been having problem making this spell.
its supposed to make a parabola.. starting with height 50, and ending in 0 with max height of 400.

The problem is when hills/cliffs are involved.. it quite messes up.
Is there any problem with the formula?

JASS:
scope Grenade

    globals
        private constant    integer     ABCD           = 'A072'
        private constant    string       FX               = "Grenade.mdx"
        private constant    real          MAX_HEIGHT  = 400
        private constant    real          MAX_RANGE   = 1200
        private constant    real          SPEED           = 700*T32_PERIOD
    endglobals

    function GetParabolaZ2 takes real x, real d, real h, real b returns real
        local real r=b-h
        local real p
        local real q
        set q=2*r*(-1-SquareRoot(1-b/r))/d
        set p=.25*q*q/r
        
        return p*x*x+q*x+b
    endfunction

    private function GetSpeed takes real range returns real
        return (range/MAX_RANGE)*SPEED*2
    endfunction

    private struct Data
    
        xefx    fx
        unit    caster
        real    x
        real    y
        real    distCur
        real    distMax
        real    heightBase
        real    speed
        real    cos
        real    sin
        integer bounce
        
        private method Destroy takes nothing returns nothing
        
            call .stopPeriodic()
            call .fx.hiddenDestroy()

            set .caster = null
            call .deallocate()
        endmethod
        
        private method Explode takes nothing returns nothing
        
            call DestroyEffect(AddSpecialEffect("PlasmaGrenade.mdx",.fx.x,.fx.y))
            call .Destroy()
        endmethod

        private method periodic takes nothing returns nothing
        
            local real i
            if .distCur+.speed > .distMax then
                set i = .distMax-.distCur
            else
                set i = .speed
            endif
                
            set .distCur    = .distCur+i
            set .x          = .x+i*.cos
            set .y          = .y+i*.sin
            
            set .fx.x   = .x
            set .fx.y   = .y
            set .fx.z   = .heightBase+GetParabolaZ2(.distCur,.distMax,MAX_HEIGHT,50)+GetHeight(.x,.y)

            //if R2I(.fx.z) == 0 then
            if .distMax == .distCur then
                call BJDebugMsg(I2S(R2I(.fx.z)))
                call .Explode()
            endif
        endmethod
        implement T32x

        private static method onCast takes nothing returns boolean
        
            local thistype  this    = thistype.allocate()
            local real      dx
            local real      dy
            local real      angle

            set .caster     = GetTriggerUnit()
            set .x          = GetUnitX(.caster)
            set .y          = GetUnitY(.caster)
            set .bounce     = 0
            
            set dx          = GetSpellTargetX()-.x
            set dy          = GetSpellTargetY()-.y
            set angle       = Atan2(dy,dx)
            
            set .sin        = Sin(angle)
            set .cos        = Cos(angle)
            set .distMax    = MinMax(SquareRoot(dx*dx+dy*dy),400,MAX_RANGE)
            set .distCur    = 0
            set .heightBase = GetHeight(.x,.y)
            set .speed      = GetSpeed(.distMax)

            set .fx         = xefx.create(.x,.y,angle)
            set .fx.fxpath  = FX
            
            call .startPeriodic()
            return false
        endmethod
        
        private static method onInit takes nothing returns nothing
            call GT_AddStartsEffectAction(function thistype.onCast,ABCD)
        endmethod
    endstruct

endscope
 
Fuck me. I have forgotten to tell you that formula depends if end/start height is the same or not.When you enter tutorial, scroll down a bit and find section 'Parabola for flat terrain', it's followed by 'Parabola for different starting and end height'. There is everything you need as explaination.

Plain parabolaZ:
JASS:
function GetParabolaZ takes real x, real d, real h, returns real
    return 4 * h * x (d -x) / (d * d)
endfunction
 
Status
Not open for further replies.
Top