UnityNinja Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

UnityNinja CommunityLog in

UnityNinja - Video Game Development Community, including Resources, Forums, Marketplace & More.


descriptionThe ball must jump only when it touches the ground EmptyThe ball must jump only when it touches the ground

more_horiz
I want that the player ball must not jump when it is in the air , but only when the ball is on the ground How do I make jump the ball only when the ball touches the ground ?

--------------

Code:

var jumpDelay : boolean;
      var doubleJump : int = 0;
      function Update()
      {
          if(Input.GetKeyDown(KeyCode.Space) && jumpDelay == false)
          {
              Jump();
          }
      }
 
      function Jump()
      {
          if (doubleJump <= 1)
          {
              rigidbody.velocity.y = 10;
              jumpTimer();
          }
      }
 
      function jumpTimer()
      {
          if (Input.GetKeyDown(KeyCode.Space))
          {
              doubleJump ++;
          }
 
          if (doubleJump > 1)
          {
              doubleJump = 0;
              jumpDelay = true;
              yield WaitForSeconds(3);
              jumpDelay = false;
          }
      }
 
 

descriptionThe ball must jump only when it touches the ground EmptyRe: The ball must jump only when it touches the ground

more_horiz
Use RaycastHit and distance
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply