How to ignore friction when setting velocity?

HI, for some reason i want to make player movement from two parts. The first is the physics part. It’s needed to make inertia and acceleration on slopes, for example. And the second one is for responsive movement, so I want to control velocity directly for this part. For this movement I made simple function witch was supposed work. I control only second part, the rigid body with low friction material should take care of the rest.

private void Move()
{
    _inputVelocity = _playerInput.Player.Move.ReadValue<Vector2>();
    _inputVelocity = new Vector3(_inputVelocity.x, 0f, _inputVelocity.y);

    if (IsGrounded())
    {
        _inputVelocity *= movementFactor;
    }
    else
    {
        _inputVelocity *= airMovementFactor;
    }
    _inputVelocity = transform.TransformDirection(_inputVelocity);
    Debug.Log(_inputVelocity);
    _rb.velocity -= _previousInputVelocity;
    _rb.velocity += _inputVelocity;

    _previousInputVelocity = _inputVelocity;
}

But this doesn’t work both in Update and FixedUpdate. It only works in case of zero friction. But I need it for proper slope slide. How do I make this right?

Remove line 16 because it could make your character go backwards instead of just stopping. It could also prevent your character from falling when in the air.

I suspect you’re just struggling getting the right balance between force and friction. Let the physics engine bring your character to a stop. You can either increase material friction or adjust the rigidbody drag. You could also set a higher drag value when on the ground by setting _rb.drag.

But how do I make responsive movement part? I think I can represent my movement with two velocity vectors. First for physics and second for responsive movement. Second velocity vector is _inputVelocity. So I just replace old _inputVelocity every Update. Falling in the air works just fine for some reason.

I think it’s because the friction applies after setting velocity in script, so I can’t set velocity ignoring friction.

Instead of messing with _rb.velocity try this:

_rb.AddForce(_inputVelocity,ForceMode.VelocityChange);

After a few experiments, I think I’ve reached desired behavior. This line of code solves the problem:

_rb.MovePosition(_rb.position + _inputVelocity * Time.deltaTime);

In this way I can move character without interfering into rigid body velocities. Thank you for help!