I'm trying to make a character jump on a landing pad who stays above him. Here is the formula I've used (everything is pretty much self-explainable, maybe except character_MaxForce that is the total force the character can jump):
deltaPosition = target - character_position;
sqrtTerm = Sqrt(2 * -gravity.y * deltaPosition.y + MaxYVelocity * character_MaxForce);
time = (MaxYVelocity - sqrtTerm) / gravity.y;
speedSq = jumpVelocity.x * jumpVelocity.x + jumpVelocity.z * jumpVelocity.z;
If speedSq < (character_MaxForce * character_MaxForce) we have the right time so we can store the value:
jumpVelocity.x = deltaPosition.x / time;
jumpVelocity.z = deltaPosition.z / time;
Otherwise we try the other solution:
time = (MaxYVelocity + sqrtTerm) / gravity.y;
and then store it:
jumpVelocity.x = deltaPosition.x / time;
jumpVelocity.z = deltaPosition.z / time;
jumpVelocity.y = MaxYVelocity;
rigidbody_velocity = jumpVelocity;
The problem is that the character is jumping away from the landing pad or sometime he jumps too far never hitting the landing pad.
