'How to apply rigidbody stopping algorithm in unity in each dimension separately

We want to have player move and rotate in 3 axis and right now we do it by changing transform.Rotate on input for rotation and rb.AddForce on input for movement. We want to stop the player after specific amount of time after they stop putting input in the current direction eg. player is pressing forward+up and stops holding up makes upward movement slowdown over a few seconds to 0 and forward movement to not slowdown. Since player can rotate in every direction we can't just set velocity on update in each direction. We'd love to be able to set exact amount of time to stop so we'd like to calculate it somehow and so far we only managed to achieve it using drag that we can't find a good formula for calculating stopping time using it. I tried to apply stopping using negative of the input axis to apply correct force vector but implementation isn't right and we're at loss at how we could accurately implement this. Here's the current stopping code:

//for each axis
for (int i = 0; i < 3; i++)
        {
            //if there is no input in that axis and velocity is not 0 in that axis
            if (Mathf.Approximately(axisVector[i], 0) && !Mathf.Approximately(rb.velocity[i], 0))
            {
                forceTemp[i] = forceVector[i];
                rb.AddForce(-forceTemp);
                Debug.Log(forceVector[i]);
                forceTemp = new Vector3(0, 0, 0);
            }
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source