How to stop cube from sliding (rg2d.velocity)

Hi all,

I’m currently busy with my charachter controller for my 2D game and like the smoothness from ‘velocity’ however i can’t seem to solve the slipping from the charachter. Is there a solution for this problem?

My code:

      float moveH = Input.GetAxis("Horizontal");
      float moveV = Input.GetAxis("Vertical");

      if (moveH > 0)
        {
            rb2D.velocity = new Vector2(moveH * maxSpeed, rb2D.velocity.y);
        }
        else if (moveH < 0)
        {
            rb2D.velocity = new Vector2(moveH * maxSpeed, rb2D.velocity.y);
        }
        else
        {
            rb2D.velocity = new Vector2(0, rb2D.velocity.y);
        }

        if (moveV > 0)
        {
            rb2D.velocity = new Vector2(rb2D.velocity.x, moveV * maxSpeed);
        }
        else if (moveV < 0)
        {
            rb2D.velocity = new Vector2(rb2D.velocity.x, moveV * maxSpeed);
        }
        else
        {
            rb2D.velocity = new Vector2(rb2D.velocity.x, 0);
        }

        Debug.Log(moveH);
        Debug.Log(moveV);
    }

Kind regards,

Ruben

A quick and simple way would be to turn on Gravity Scale which will pull the object down to the colliders and slow it down due to collision. Another would be to create a Physics 2D Material and assign it in the Material Slot of the Rigid-body component in it you can control the amount of friction and bounciness the user experiences.