This is my first 3D game ever, and I’m struggling with the character movement.
I used code straight off of a Brackey’s tutorial, because I don’t exactly know how to code yet, and my player now has a sort of delay between every time I press a movement key and when I actually move, and it kind of slides to a stop across the floor like ice when I’m done moving.
I want to get rid of the delay and the slide, so is there any way I can do that?
Here’s Brackey’s code for character movement:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterMovement : 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);
}
}
Sorry if I did something wrong with the copy and pasting, I don’t know what I’m doing.
Thanks!