- Home /
The character fails to jump sometimes
Hello, I am using this script to make a ball role and jump and it is working. However, sometimes then i try to jump, while I am also pressing s and d to role, it will not jump. Is there anything that i can improve to make it work better? I hope that you can help me. Frederik
pragma strict
 var speed : float;
 var forward : KeyCode;
 var backward : KeyCode;
 var right : KeyCode;
 var left : KeyCode;
 var jumpForce : float;
 var jump : KeyCode;
 private var isFalling = false;
 
 function FixedUpdate ()
 {
     if(Input.GetKeyDown(jump) && isFalling == false)
     {
         rigidbody.velocity.y = jumpForce;
     }
     isFalling = true;
     //Handle ball rotation
     if(Input.GetKey(forward))
     {
         rigidbody.AddForce(Vector3.forward*speed);
     }
     if(Input.GetKey(backward))
     {
         rigidbody.AddForce(-Vector3.forward*speed);
     }
     if(Input.GetKey(right))
     {
         rigidbody.AddForce(Vector3.right*speed);
     }
     if(Input.GetKey(left))
     {
         rigidbody.AddForce(Vector3.left*speed);
     }
 }
 function OnCollisionStay ()
 {
     isFalling = false;
 }
Answer by AndyMartin458 · Jan 11, 2014 at 01:12 AM
I don't know if it will fix everything, but I think that you you should set isFalling to true only when you have jumped, instead of every time.
 if(Input.GetKeyDown(jump) && isFalling == false)
 {
     rigidbody.velocity.y = jumpForce;
     isFalling = true;
 }
Thanks for your reply, but this did unfortunatly not fix anything. In fact, it made me able to double jump.
@FrederikBak haha wow that is unexpected. Did you ever get it resolved?
@FrederikBak you should only be taking that input in Update. I had an issue with taking ButtonDown input in FixedUpdate where a lot of the input would be missed. See the reasoning here: http://answers.unity3d.com/questions/618011/23-times-pressing-a-button-does-nothing.html
Your answer
 
 
             Follow this Question
Related Questions
HELP! stuck on wall jump Unity 2D 1 Answer
Help with jump script PLEASE :( 0 Answers
How do you double jump in a 2d game 1 Answer
Why Won't it jump? 1 Answer
How to ground the player after jump animation completes 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                