My player only jumps once

Hello everybody! So I’ve been trying to debug this code, I’m new to Unity and C# so really not sure why my player only jumps once.

I’m able to press the space bar and make it jump, but it doesn’t jump again after that, here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    //Components
    private Rigidbody playerRb;
    private Animator playerAnim;
    private AudioSource playerAudio;

    //Values
    public float jumpForce = 15;
    public float gravityModifier;


    //Booleans
    public bool isOnGround = true;
    public bool gameOver = false;

    // Start is called before the first frame update
    void Start()
    {
        playerRb = GetComponent<Rigidbody>();
        playerAnim = GetComponent<Animator>();
        playerAudio = GetComponent<AudioSource>();
        Physics.gravity *= gravityModifier;
    }

    // Update is called once per frame
    void Update()
    {
        //the following "if" statement obtains the input from the user
        if (Input.GetKeyDown(KeyCode.Space) && isOnGround && !gameOver)
        {
            //Here we make the player jump
            playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
            isOnGround = false;
        }
    }

    private void onCollisionEnter(Collision collision)
    {
        //Here we make the groundcheck
        isOnGround = true;

        if (collision.gameObject.CompareTag("Ground"))
        {
            isOnGround = true;
        }
    }
}

Does the player have a rigidbody component, if it does is it checked or unchecked

1 Like

onCollisionEnter is not a thing in Unity. Please make sure to spell things correctly.

1 Like

Thank you so much for your reply! Yes it does, see here:
8653095--1164663--upload_2022-12-11_15-34-11.png

As I said, I’m new at this, I really don’t even know what you meant by “is not a thing”, people don’t use it? It doesn’t work? How would you write it?

Compare your spelling of the method to this:
https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

(Study it closely! And keep in mind C# is case-sensitive. Upper/lowercase characters matter.)

1 Like

I discovered that the “Is On Ground” bool doesn’t checks again as “true” after the player jumps, it stays unchecked

8653113--1164666--upload_2022-12-11_15-38-27.png

Aaaaawesome! I saw the error, thank you so much!! Is working now :smile:

1 Like