All the basic kinematic equations of physics are all you need. Despite the fact that the questions had already been answered, if I were you, I still did it manually, because using the library seems redundant. Run the equation for speed:
velocity = initial velocity + (acceleration * time)
From there we integrate to find the position:
position = initial position + (initial velocity * time) + (acceleration * time^2)/2
Your jump is designed to calculate the y-position of the character, so just use this equation to calculate the y-position and the toy with an initial speed and acceleration. The standard acceleration due to gravity is -9.8 meters per second ^ 2 (at least on the surface of the earth - these are different different planets of the planet). Start from the starting position regardless of your character, or 0 if the earth is 0.
So:
y = vt + (-4.9)t^2
Choose an initial speed v to provide upward movement at the start of the jump, and t should be the elapsed playing time since it started to jump.
For this you need only one line of code, no libraries needed!
EDIT: what to do when you land.
So, in the real world, acceleration is caused by unbalanced forces. Gravity always acts on you, but when you stand in the earth, it is counteracted and canceled by the "normal force" of the earth. As long as the ground you are standing on is strong enough to support your weight, the ground will push back and resist gravity, and you will not accelerate down. Therefore, in your game, if you are not really simulating forces, simply change the acceleration from -9.8 to 0 when your character touches the ground. If the ground is flat, your jump ends when position = initial position
Chuck dries
source share