How can I add counter movement to Character Controller Movement.

I’m making 2D, top-down movement and I’m using the character controller component. It works fine but when I stop moving the player slides around. This also happens when changing direction, which makes it unresponsive and frustrating to play. Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    
    public float moveSpeed;
    public CharacterController controller;

    // Update is called once per frame
    void Update()
    {
        float x = Input.GetAxis("Horizontal") * moveSpeed;
        float y = Input.GetAxis("Vertical") * moveSpeed;

        Vector3 move = new Vector3(x , y , 0);
        controller.Move(move);
        
    }
}

When using “Input.GetAxis” yo don’t get a value of 0 or 1 immediately, you get intermediate values when pressing or “unpressing” a key. That’s why your character slides.

If you want to get only 0 or 1 values, try using “Input.GetAxisRaw”, this way you wont get the intermediate values avoiding the slide.

Extra hint:
When working with speeds, i’d recomend using deltaTime aswell, so the game’s framerate doesn’t mess with your character’s speed.

float x = Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime;
float y = Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime;