Character Sliding

my character is sliding in this script i dont know how to make him walk normally

#pragma strict
var playerAcceleration : float = 500;
var cameraObject : GameObject;
var maxSpeed : float = 20;
var horizontalMovement : Vector2;
var deaceleration : float;
var deacelerationX : float;
var deacelerationZ : float;
var jumpSpeed : float = 20;
var maxSlope : float = 60;
var grounded : boolean = false;

function Update ()
    {
       horizontalMovement = Vector2(rigidbody.velocity.x,rigidbody.velocity.z);
       if (horizontalMovement.magnitude > maxSpeed)
           {
               horizontalMovement = horizontalMovement.normalized;
               horizontalMovement *= maxSpeed;
           }
       rigidbody.velocity.x = horizontalMovement.x;
       rigidbody.velocity.z = horizontalMovement.y;
      
       if (Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0)
           {
              rigidbody.velocity.x = Mathf.SmoothDamp(rigidbody.velocity.x,0,deacelerationX, deaceleration);
              rigidbody.velocity.z = Mathf.SmoothDamp(rigidbody.velocity.z,0,deacelerationZ, deaceleration);
           }
       transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLook).CurrentYRotation,0);
       rigidbody.AddRelativeForce(Input.GetAxis("Horizontal")*playerAcceleration * Time.deltaTime,0,Input.GetAxis("Vertical")*playerAcceleration * Time.deltaTime);
       if (Input.GetButtonDown("Jump")&& grounded)
           {
               rigidbody.AddForce(0,jumpSpeed,0);
           }
    }
function OnCollisionStay(collision : Collision)
    {
        for (var contact : ContactPoint in collision.contacts)
             {
                 if (Vector3.Angle(contact.normal, Vector3.up) < maxSlope)
                     {
                         grounded = true;
                     }
             }
     }
function OnCollisionExit()
    {
        grounded = false;
    }

Try to freeze your X, Y and Z rotations in Rigidbody, by:

  1. Click on rigidbody component
  2. Click on “constraints” (should be at the bottom or something)
  3. Tick the lower three ones, a.k.a X, Y and Z.

Tried that didnt work

Try to delete the slope effect from your script. Slope is basically when the player is sliding when standing on a higher point than zero, and this may be bugged for you. Try to delete everything that has to do with slope in your script.