3d player movement sliding to stop

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!

GetAxis() will automatically “smooth” your values between -1, 0, and 1, so it will cause a slow-ish stop or start. If you wanted to get the direct values, you can use GetAxisRaw() instead, as this only returns the exact values.

1 Like

Me neither but I rarely let it slow me down.

What Panda says above is likely a good first clue to investigate.

You can also get turnkey FPS scripts such as this one:

https://discussions.unity.com/t/855344

That one has run, walk, jump, slide, crouch… it’s crazy-nutty!!

1 Like

Thank you, this fixed my issue!

I’ll definitely check this out. Thank you.