Character wont jump

Following this guide one youtube

(starts at 21:50)
followed it exactly, or at least I think, but my character wont jump. I can walk around, turn, and have gravity but no jumping

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

public class playermovementscript : MonoBehaviour
{
    public CharacterController controller;

    public float speed = 12f;
    public float gravity = -9.81f;
    public float jumpHeight = 3f;

    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;


    Vector3 velocity;
    bool isGrounded;

    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if(isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }

        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;

        controller.Move(move * speed * Time.deltaTime);

        if(Input.GetButtonDown("Jump") && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }

        velocity.y += gravity + Time.deltaTime;

        controller.Move(velocity * Time.deltaTime);
    }
}

Make isGrounded public and watch its value in the inspector. Is “isGrounded” ever set to true? If not, you may not have set up your layers or masks correctly.

I apologize, I just started learning this stuff. what do you mean make isGrounded public?

Put the word “public” in front of line 19, just like the fields above it like groundMask. If you look at that in the Inspector, you will now see a checkbox; that checkbox will be checked if the boolean is “true” and unchecked if it’s “false”.

Interestingly, it appears recent versions of Unity no longer work with this approach, calling .Move() twice.

I did an investigation about it and reported my findings here:

In that post I also fixed the default Unity movement script example from the CharacterController script reference page. It appears the script above is somewhat derivative of that original broken script, at least inasmuch as it calls .Move() twice.