Rigidbody controller counter movement

Basically I’m doing a FPS controller with a rigidbody, since I want the movement to have physics involved. But I’m kind of a noob and I am not able to add some counter movement so when the player is on the ground, they can controll themselves better and not slide around everywhere.
This is what I currently have:
#region Variables
public CameraMovement camera;

    public int speed = 20;
    public int maxSpeed = 20;
    public int slowDownFactor = 10;
    private float hMovement;
    private float vMovement;
    private Vector2 movement;
    private Vector2 prevMovement;
    private bool jumping;

    public int jumpForce = 10;
    public int extraGravity = 10;

    private Rigidbody player;
    private CapsuleCollider collider;


    #region Unity Callbacks
    // Start is called before the first frame update
    void Start()
        player = GetComponent<Rigidbody>();
        collider = GetComponent<CapsuleCollider>();

    // Update is called once per frame
    void FixedUpdate()

        if (Input.GetKeyDown(KeyCode.Q)) Debug.Log(Grounded());

    #region My methods

    //The player movement
    private void Movement()
        //Gets the input
        hMovement = Input.GetAxisRaw("Horizontal");
        vMovement = Input.GetAxisRaw("Vertical");

        movement = new Vector2(hMovement, vMovement);

        jumping = Input.GetButton("Jump");

        //If the movement is more than the maximum, cancel out the input(x)
        if (player.velocity.x > maxSpeed && hMovement > 0) hMovement = 0;
        if (player.velocity.x < -maxSpeed && hMovement < 0) hMovement = 0;

        //If the movement is more than the maximum, cancel out the input(z)
        if (player.velocity.z > maxSpeed && vMovement > 0) vMovement = 0;
        if (player.velocity.z < -maxSpeed && vMovement < 0) vMovement = 0;

        if (jumping && Grounded())
            player.AddForce(new Vector3(0, jumpForce, 0), ForceMode.Impulse);

        //Adds the force to the rigidbody
        player.AddForce(hMovement * transform.right * Time.deltaTime * speed, ForceMode.Impulse);
        player.AddForce(vMovement * transform.forward * Time.deltaTime * speed, ForceMode.Impulse);

        //Extra gravity
        player.AddForce(new Vector3(0, -extraGravity, 0));

    //The counter movement, to avoid sloppy movement
    private void CounterMovement()
        Vector3 counterMovement = new Vector3(-player.velocity.x, 0, -player.velocity.z);

        if ((prevMovement.x != movement.x || prevMovement.y != movement.y) && Grounded())
            //Add some counter movement if the player has stopped pressing a movement key, or pressed a new one
            player.AddForce(counterMovement * 40);
            prevMovement = movement;


    //Rotates the player on the y with the mouse
    private void Rotate()
        transform.rotation = camera.playerRotation;

    //Determins if the player is grounded
    private bool Grounded()
        return Physics.Raycast(transform.position, Vector3.down, collider.bounds.extents.y + .1f);


I’ve been stuck on this for a long time, so I finally decided to ask for help. Thanks in advance.

Have you tried adding a PhysicsMaterial to your ground surface collider? That should allow you to increase the surface friction values which would hopefully achieve the effect you’re describing. It would also play nice with the physics engine which is always a nice bonus :slight_smile:

Edit: My other suggestion would be to set the rigidbody’s linear drag to a suitably high value when you want to slow it down rapidly:

if ((prevMovement.x != movement.x || prevMovement.y != movement.y) && Grounded())
    player.drag = COUNTER_DRAG;
    player.drag = DEFAULT_DRAG; // probably 0.0f, but it's always good to avoid those hard coded constants...