Help please (810594)

Help my character is jumping infinitly what to do I found the code on youtube brackeys channel im super new to programming.
Here is the code

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

public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;

public float speed = 10f;
public float gravity = -10f;
public float jumpHeight = 5f;

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

Vector3 velocity;
bool isGrounded;

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.GetButton(“Jump”) && isGrounded){
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}

velocity.y += gravity * Time.deltaTime;

controller.Move(velocity * Time.deltaTime);

}
}

Hey there,

Could you link the video/tutorial? Also, would be handy to understand what version of the Editor you are using :slight_smile:

Use Debug.Log. Check what the value of isGrounded is. Check if the “Jump” button is being pressed when you expect it not to be pressed. Output the value of velocity.y. “gravity” is a public field, so make sure it is set to a negative number, such as -10f, in the inspector. A positive gravity value would result in just flying away whenever not jumping. etc, etc, etc good luck

UnityMaru this

Im using 2019.4.11

Joe Censored how do you check the value of IsGrounded im very new to unity

I can jump while in the air what to do

Judging by the YouTube comments, a lot of users are running into the same problem. You may want to look through those comments for a solution.