Rigidbody Player gets stuck on walls when jumping

So, I am working on a fps controller that uses a rigidbody instead of Unity’s Character Controller. I am currently running into a problem where when the player jumps then touches a wall, they will stop moving upward for a second before falling.


I have discovered that the player is still doing their full jump, but won’t go any higher when touching a wall. I also discovered that using Rigidbody.AddForce causes this problem only. Rigidbody.MovePosition won’t. I’m trying to figure out how to do this without using a Physics material on every collidable object in the game


Here is my movement code

private void Update()
    {
        float v = Input.GetAxis("Vertical") * MoveSpeed;
        float h = Input.GetAxis("Horizontal") * StrafeSpeed;

        velocity = new Vector3(h, velocity.y, v);
        velocity = transform.TransformDirection(velocity);

        if (IsGrounded())
        {

            if (Input.GetKeyDown(KeyCode.Space))
            {
                RB.AddForce(transform.up * Mathf.Sqrt(JumpModifier * JumpForce * Gravity));
            }
        }

    }

    private void FixedUpdate()
    {
        RB.MovePosition(RB.position + velocity * Time.deltaTime);
    }

Just assign the material on the player maybe? that way you avoid doing it on the all the other stuff

Assign a physics 2d material to your character then set the friction to zero on the material

So, I’m now doing two things, using AddForce and using a PhysicsMaterial. So, here is my code for adding force to the player’s movement

var velocity = m_Rigidbody.velocity;
var velocityChange = moveDirection - velocity;

velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0;

m_Rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);

maxVelocityChange is just a float variable I have currently set to 20. Along with this, I do apply a PhysicsMaterial to the player with a friction of 0. This removes the issue of getting stuck on walls and the player can move fairly freely

This might help as well:

I found out that using “Platform Effector 2D” also helps.

The help states:
“The Platform Effector 2D applies various platform behavior such as one-way collisions, removal of side-friction/bounce and more.”