Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Jump code

Discussion in 'Scripting' started by Jean-Jacque_Jiquenschwees, Jul 19, 2022.

  1. Jean-Jacque_Jiquenschwees

    Jean-Jacque_Jiquenschwees

    Joined:
    Jul 18, 2022
    Posts:
    29
    Does anybody know why my jump code isn´t working
    Code (CSharp):
    1.  
    2. [SerializeField] float jumpForce = 5f;
    3.  
    4.     void Start()
    5.     {
    6.           rb = GetComponent<Rigidbody>();
    7.     }
    8.         if (Input.GetButtonDown("jump") && IsGrounded())
    9.         {
    10.             Jump();
    11.         }
    12.  
    13.     void Jump()
    14.     {
    15.         rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
    16.     }
     
  2. Jean-Jacque_Jiquenschwees

    Jean-Jacque_Jiquenschwees

    Joined:
    Jul 18, 2022
    Posts:
    29
    The if statement is in void update
     
  3. Sphinks

    Sphinks

    Joined:
    Apr 6, 2019
    Posts:
    267
    It´s hard to say anything without seeing the whole code. But did you ever check if the value of "IsGrounded" is true ?
     
  4. Nefisto

    Nefisto

    Joined:
    Sep 17, 2014
    Posts:
    324
    Can be a bunch of things, a) typo in "jump" b) "jump" is not being assigned in settings c) isGrounded is never true and some other, we need more info
     
  5. Jean-Jacque_Jiquenschwees

    Jean-Jacque_Jiquenschwees

    Joined:
    Jul 18, 2022
    Posts:
    29
    Thanks i watched and the ground was nothing that's why it was never grounded