using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
private CharacterController mover;
[SerializeField] private float speed;
private Vector3 velocity;
[SerializeField] private float gravity = -9.81f;
[SerializeField] private Transform groundCheck;
[SerializeField] private float groundDistance = 0.4f;
[SerializeField] private LayerMask groundMask;
private bool isGrounded;
private void Start()
{
mover = GetComponent<CharacterController>();
}
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundMask, groundMask);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
Debug.Log("Setting velocity low");
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
mover.Move(move * speed * Time.deltaTime);
velocity.y += gravity * Time.deltaTime;
mover.Move(velocity * Time.deltaTime);
}
}
I’m trying to make gravity for a character controller. However, when the player jumps off, it takes around 4 seconds for the gravity to kick in. I’m pretty sure it’s because the isGrounded variable doesn’t turn false for around 4 seconds after the player jumps. I know because of the debug statement on line 28.
Also just so you know I’m following this tutorial: