[JASS] Looking For Right Formula

Discussion in 'Triggers & Scripts' started by Megafyr, Dec 23, 2010.

1. Megafyr

Joined:
Oct 29, 2007
Messages:
957
Resources:
1
Tutorials:
1
Resources:
1
I am trying making a jump system that changes a units flying height in a lifelike way, without interference from the grounds z value. The jump increases the unit z with velocity v. Then gravity pulls the unit down with accelleration a=g. The problem occurs where the the terrain height from the start to the end of the jump changes. (The unit may be changing x and y while jumping.)

I think the formula for height h should be like this for each change in time t: h(t) = hunit flying height current + hchange in terrain from origin to end of jump + hvelocity v - hgravitity g

This, however, creates some very strange changes in the units z value where sometimes the unit u would jump 10 x its own height into the air, and other times it would hardly jump at all, given the grounds z changes from origin to end. Where the grounds z doesn't change, the formula seems to be correct.

Can someone help me adjust this formula correctly? I think I might not have the change in terrain z thing right.

Code Moderator

Joined:
Nov 11, 2006
Messages:
7,426
Resources:
18
Icons:
1
Spells:
4
Tutorials:
9
JASS:
4
Resources:
18

Code (vJASS):
library ParabolicMovement2

function ParabolaZ2 takes real y0, real y1, real h, real d, real x returns real
local real A = (2*(y0+y1)-4*h)/(d*d)
local real B = (y1-y0-A*d*d)/d
return A*x*x + B*x + y0
endfunction

endlibrary

y0 = z initial, y1 = z final. h = max height, d = total distance, and x is the distance from the unit's start to it's current position at that instance.

3. D4RK_G4ND4LF

Joined:
Feb 4, 2009
Messages:
1,196
Resources:
20
Models:
3
Spells:
15
Tutorials:
2
Resources:
20
I wrote a tutorial about it some time ago
(see signature)
Code (vJASS):
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

4. Megafyr

Joined:
Oct 29, 2007
Messages:
957
Resources:
1
Tutorials:
1
Resources:
1
Thanks for the reply guys. I got it right now.