- Home /
Jump with mathf.lerp problem
Hello,
i want my player to jump using mathf.Lerp.
I already managed to make him jump, but he doesn't fall again. What's wrong with my script?
function Update () {
transform.Rotate(0,0,Input.GetAxis("Horizontal") * speed * Time.deltaTime);
player.transform.localPosition.y = newPos;
if(Input.GetKeyDown(KeyCode.Space))
{
jumping = true;
}
if(jumping)
{
Jumper();
}
}
function Jumper () {
timer += Time.deltaTime * jumpSpeed;
timerFall += Time.deltaTime * jumpSpeed;
newPos = new Mathf.Lerp(startPos, startPos + jumpHeight, timer * jumpSpeed);
yield WaitForSeconds(0.5);
newPos = new Mathf.Lerp(startPos + jumpHeight, startPos, timerFall * jumpSpeed);
}
Answer by Xtro · Aug 06, 2013 at 04:01 PM
you don't cancel the jumping by setting the jumping = false;
instead of if check, just use this:
jumping = Input.GetKeyDown(KeyCode.Space);
this will set it true or false according to space key.
ins$$anonymous$$d of this part:
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
{
jumping = true;
}
Answer by tamimsaiyed · Sep 05, 2015 at 04:17 PM
Ok, this is a really old post, and you've probably already figured it out by now, but since you are using: yield WaitForSeconds(0.5); Shouldn't your Function be written as: function Jumper() : IEnumerator { ...... } and your Function call as: if(jumping) { StartCoroutine(Jumper()); } ???
He's using javascript. Not C#. In javascript(UnityScript actually) you don't need to define IEnumerator type for the function.
Oh ok, my bad then, recently changed some C# code into JavaScript and kept IEnumerator type as a precaution, so thanks for the update.
Your answer
Follow this Question
Related Questions
how to use time on lerp 2 Answers
Time.deltaTime making color lerp appear fast, but won't reach 1 1 Answer
Trying to lerp in different states in a switch statement 0 Answers
Mathf.Lerp Question 2 Answers