- Home /
Jump Distance
how can i make a frog jump same distance every time.
eksample.
i want the frog jump from position.z 0.0 to 2.0 and if i press the button it jump to 4.0
my problem is the i can make the frog change position but i want the jump effect (not just change position)
What language, C# or Javascript? Seriosuly, this should be a site rule: "Always tag your post with the language you are working in!"
Answer by syclamoth · Jan 17, 2012 at 09:50 AM
What you want is some kind of parabolic curve for when the frog jumps. If you know the target position, you can do something like this:
function JumpForward(targetPos : Vector3)
{
var startPos : Vector3 = transform.position;
var height : float = 0;
var verticalVelocity : float = jumpPower;
var curTime : float = 0;
while(curTime < jumpTime)
{
height += verticalVelocity * Time.deltaTime;
verticalVelocity = Mathf.Lerp(jumpPower, -jumpPower, curTime / jumpTime);
var basePos : Vector3 = Vector3.Lerp(startPos, targetPos, curTime / jumpTime);
var resultantPos : Vector3 = basePos + (Vector3.up * height);
transform.position = resultantPos;
curTime += Time.deltaTime;
yield;
}
}
Hey Syclamoth
it seem to work perfect....
A big thanks to you.
Best Regards
$$anonymous$$
i tried this one it seems like the jumping is no a like parabola.I need the same jump with parabola shape .
could u tell me how can i do it.
Your answer
Follow this Question
Related Questions
Jump on button press. [JavaScript] 1 Answer
2D Character Jumps only 1 time 2 Answers
Ball jumping mechanic, scrip errors. 1 Answer
How come my player animation won't play? 1 Answer
how to jump with 2d? 1 Answer