- Home /
Begginer Jumping javascrpit problem.
I am making my first game in unity and do not have a lot of coding experience with java script. The game i can making is a simple ball rolling platformer. If i spam the jump button (w) my ball jumps the first time then when it lands it does not jump right away but it jumps randomly after a number of button presses. Here is the code.
pragma strict
 var rotationSpeed = 100;
 var jumpHeight = 8;
  
 private var isFalling = false;
  
 function Update ()
 {
     //Handle ball rotation.
     var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
     rotation *= Time.deltaTime;
     rigidbody.AddRelativeTorque (Vector3.back * rotation);
    
     if (Input.GetKeyDown(KeyCode.W) && isFalling == false)
     {
         rigidbody.velocity.y = jumpHeight;
     }
     isFalling = true;
 }
  
 function OnCollisionStay ()
 {
     isFalling = false;
 }
Not related to the question- This code looks really familiar, did you by any chance get it from a Brackeys tutorial?
Yes i did. Im also not sure where to put rigidbody.velocity = Vector3.zero; rigidbody.angularVelocity = Vector3.zero;
Answer by brockk · Aug 26, 2014 at 09:23 AM
Set velocity to 0 when ball lands
rigidbody.velocity = Vector3.zero; rigidbody.angularVelocity = Vector3.zero;
Yes i did. Im also not sure where to put rigidbody.velocity = Vector3.zero; rigidbody.angularVelocity = Vector3.zero;
Your answer
 
 
             Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
3D Platform Controller Forward & Camera HELP! 2 Answers
2.5 platformer sprite animated character 3 Answers
stop song and play song 0 Answers
knockback 3d c# 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                