How to move sideaways while colliding?

Hello!

How can I make the player able to move sideways while colliding in front? (Like pressing W, colliding, but if you press A or D you can move to the left/right). If I collide with a wall straight forward and keep pressing W, I cannot move sideaways while pressing A or D, and I want the player to be able to.

This is my code for player movement.

private void movePlayer()
{
    moveDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;

    Vector3 moveForce = moveDirection.normalized * moveSpeed;

    rb.AddForce(new Vector3(moveForce.x, 0, moveForce.z), ForceMode.VelocityChange);
}

Sounds like perhaps friction is too high. Use a PhysicMaterial to make those collisions slippery.

If you’re just writing yet another player controller, you may wish to start from some working examples otherwise you’ll be reinventing all the wheels.

Here’s the go-to prototype CharacterController-based FP controller I always use to start:

It has run, walk, jump, slide, crouch… it’s crazy-nutty!!