My character dont want to jump!

My character dont want to jump and i dont know why!!!

5350197–540372–playermovement.cs (1.17 KB)

Don’t make people download files, post your code here, using code tags.

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

public class playermovement : 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);
    }

can you help?

Add Debug.Log statements outputting the value of isGrounded. Verify in the input manager that you actually have “Jump” assigned to the correct button, or switch line 38 temporarily to a specific KeyCode. Add Debug.Log before line 40 to verify that “if” statement is ever returning true. Manually work through the math of line 40 to verify the result is going to be significantly higher than “gravity * Time.deltaTime” you apply on line 43 (to verify you aren’t just cancelling out a small jump when you apply gravity).

Why are you calling controller.Move twice on the same Update? I’d venture a guess that isn’t an expected use case for CharacterController.Move, though the limited documentation doesn’t specifically say so. Though the documentation’s example which combines all deltas before issuing a single Move implies a single call to Move is how it is expected to be used.

its working now thanks