Buggy Collision

I’m trying to make a game where the player can move in 4 directions, up, down, left, and right. My game is basically a slider puzzle. I’ve managed to make it work, however when it comes to collision with other objects the game bugs a bit. I’ll be using a box collider, using a cube as the player and obstacles, and if i move up and just happen to brush aside another none moving cube the player stops either on the beggning of its edge or halfway through it. I’ve changed the collider from a box to sphere and this friction doesn’t happen as much, however it still exists. I’ve tried putting a material on it and setting it’s friction to 0 and it still continues. I have no ideia how to fix this, what can I do now?

This is my code

Blockquote

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PcTest : MonoBehaviour
{
// Start is called before the first frame update
public float x, y, speed = 20f, pressed, pres1 = 1f, pres2 = 1f, pres3 = 1f, pres4 = 1f, distance = 1f;
public bool up, left, down, right, moving, limitup, limitdown, limitleft, limitright,
collided, clicked, stopped, cantup, cantdown, cantright, cantleft, tester;
public Rigidbody rb;
public Vector2 vel;
public float timer = 1f;
public float lastx, lasty;
public bool elevator;
public int counter;
public GameObject door2;
public bool coli;
public Vector3 stopPos;
// Use this for initialization
void Start()
{
stopped = true;
rb = GetComponent();
lastx = transform.position.x;
lasty = transform.position.y;
}

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

    if (coli)
    {
        counter += 1;
        coli = false;
    }
    if (counter >= 2) { Destroy(door2); }
    x = Mathf.Round(rb.velocity.x * 100) / 100;
    y = Mathf.Round(rb.velocity.y * 100) / 100;

   
    if (!moving)
    {
        if (Input.GetKey("up") && !cantup )
        {
            rb.isKinematic = false;

            down = false;
            up = true;
            left = false;
            right = false;
            stopped = false;
            moving = true;
        }
        else
        if (Input.GetKey("down") && !cantdown  )
        {
            rb.isKinematic = false;

            down = true;
            up = false;
            left = false;
            right = false;
            stopped = false;
            moving = true;
        }
        else
        if (Input.GetKey("right") && !cantright  )
        {
            rb.isKinematic = false;

            down = false;
            up = false;
            left = false;
            right = true;
            stopped = false;
            moving = true;

        }
        else
        if (Input.GetKey("left") && !cantleft  )
        {
            rb.isKinematic = false;

            down = false;
            up = false;
            left = true;
            right = false;
            stopped = false;
            moving = true;

        }
    }

    if (!stopped )
    {
        if (up && !cantup)
        {
            //  rb.velocity = new Vector3(0, 15, 0);

            rb.AddForce(transform.up * speed);
            rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationZ
                | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationX;
          

        }

        if (down && !cantdown)
        {
            //  rb.velocity = new Vector3(0, -15, 0);

            rb.AddForce(-transform.up * speed);
            rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationZ
                               | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationX;

        }

        if (right && !cantright)
        {

            rb.AddForce(transform.right * speed);
            //  rb.velocity = new Vector3(15, 0, 0);

            rb.constraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationZ
                               | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationX;

        }

        if (left && !cantleft)
        {

            rb.constraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationZ
                               | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationX;

            rb.AddForce(-transform.right * speed);
            // rb.velocity = new Vector3(-15, 0, 0);

          

        }
    }

    if (x == 0f && y == 0f)
    {
        stopped = true;
        moving = false;
        down = false;
        up = false;
        left = false;
        right = false;
        clicked = false;

    }
    else { stopped = false; }

}



void OnCollisionEnter(Collision col)
{

    if (col.gameObject.tag == "Player")
    {
        rb.isKinematic = true;
        //rb.velocity = Vector3.zero;
        stopped = true;
        moving = false;
        down = false;
        up = false;
        left = false;
        right = false;
        clicked = false;
    }

    if (col.gameObject.tag == "key")
    {

        right = false;
        left= false;
        up = false;
        down = false;

    }

}

}

This should address your issues.