Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
1  
You know whether the landing path is left or right by comparing the "x" value. Or you could simply calculate a default trajectory between the two pads. But if you don't want to couple the jump and landing pads then you could simply specify a direction vector in your jump pad and a scalar ( a multiplier ) that acts as a velocity to your character making him jump in a certain direction. Tweaking the scalar and riection should give you the right trajectory. –  Sidar Sep 26 '12 at 23:17
1  
And by default trajectory I mean using a Quadratic Bezier curve. You know the starting point(jump pad) and the end point(landing pad). Using the control point, which can never be lower than the highest pad, to define your "curve". en.wikipedia.org/wiki/B%C3%A9zier_curve Look at the quadratic formula, it's very simple. ( this will only give you the curve though) Using "t" to trace the curve (which is between 0 an 1 ) –  Sidar Sep 26 '12 at 23:23
    
Man I love the game dev because they have always a simple but smart solution thanks a lot man, I will try to implement this and let you now :D –  Pasquale Sada Sep 27 '12 at 8:50
    
@Sidar you should post all this as an answer. –  Laurent Couvidou Nov 26 '12 at 9:26
    
@LaurentCouvidou Done =) thanks. –  Sidar Nov 26 '12 at 13:49
add comment

1 Answer

You know whether the landing path is left or right by comparing the "x" value. Or you could simply calculate a default trajectory between the two pads. But if you don't want to couple the jump and landing pads then you could simply specify a direction vector in your jump pad and a scalar ( a multiplier ) that acts as a velocity to your character making him jump in a certain direction. Tweaking the scalar and direction should give you the right trajectory.

And by default trajectory I mean using a Quadratic Bezier curve. You know the starting point(jump pad) and the end point(landing pad). Using the control point, which can never be lower than the highest pad, to define your "curve".

Look at the quadratic formula, it's very simple. ( this will only give you the curve though) Using "t" to trace the curve (which is between 0 an 1 ).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.