# [vJASS]Parabola problem

Status
Not open for further replies.

#### pks9067

Level 3
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:

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 .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
endmethod
endstruct

endscope

#### Bannar

Code Reviewer
Level 26

JASS:
function GetParabolaZEx takes real x, real d, real h, real z0, real zd returns real
return 4 * h * x * (d -x) / (d * d) + x * (zd-z0) / d + z0
endfunction

#### pks9067

Level 3
Thank you. Mind explaining what are z0 and zd for?

#### Bannar

Code Reviewer
Level 26
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

#### pks9067

Level 3
doesnt explain =(

#### Bannar

Code Reviewer
Level 26
* d - distance between starting and end point
* x - distance between starting point and the missile
* h - maximal height
* zd - height of destination point
* z0 - height of starting point

Reading proves to be hard for human kind.

Status
Not open for further replies.

Replies
14
Views
1K
Replies
2
Views
601
Replies
12
Views
952
Replies
5
Views
553
Replies
1
Views
585