JumpStrength and gravity

While I understand the need for them (the Y position being calculated with a similar logic to :

Y=0.5*gravity*relativetime^2 - JumpStrength*relativetime + InitialY )

those are still unclear values for the actual person choosing it, we would rather set the height of the jump and how fast the jump is...

And there are ways to do it!

Just have this in mind, H is the height of the jump, T is the time to go from start of the jump to top of the jump, and calculate the values with:

- Code: Select all
`Jump strength = 2H/T`

Gravity = 2H/(T^2) = JumpStrength/T

You want a 300 pixels high jump that take 0.5 seconds to reach those 300 px?

then you need

- Code: Select all
`JumpStrength of 2×300/0.5 = 1200`

Gravity of 2×300/(0.5^2) = 2400

Of course, since the trajectory is not a smooth curve, but a discrete one (since C2 calculates the values at given times), expect it to be slightly imprecise with the framerate, and so do not have a 300px platform to jump on if the jump height is 300px, still a good ballpark figure that you can affect if you want.

for those who want to calculate everything, not just the jump strength and gravity, here's the math part (you need to know two values to calculate the others):

- Code: Select all
`JumpStrength = T*Gravity`

JumpStrength = sqrt(2*H*Gravity)

JumpStregth = 2*H/T

Gravity = JumpStrength/T

Gravity = (JumpStrength^2)/(2*H)

Gravity = 2*H/(T^2)

T = JumpStrength/Gravity

T = 2*H/JumpStrength

T = sqrt(2*H/Gravity)

H = (JumpStrength^2)/(2*Gravity)

H = JumpStregth*T/2

H = Gravity*(T^2)/2