Limit drag over direction

Hello
is there a way to constraint drag only on a certain direction?
For example, I want the player to slide with no drag on his relative x component, while receiving a drag on the y component of his direction.
In case this isn’t directly possible in Unity, does anyone know how drag is implemented so to create a personal drag function?
Thank you.

You can think of drag as a force applied in the opposite direction to which the body is moving, so in -v direction if v is the velocity of the rigidbody. So in the simplest case, you can just apply

float d = 1.0; // drag coefficient
Rigidbody.AddForce(- d * Rigidbody.velocity, ForceMode.Force);

But if you want no drag in x direction, you could write instead

Rigidbody.AddForce(- d * new Vector3(0f, Rigidbody.velocity.y, Rigidbody.velocity.z), ForceMode.Force);
1 Like

First set Unity build in drag coef to 0.
then handle drag yourself like this.

public float YdragCoeff;

Vector3 velocity = Rigidbody.GetPointVelocity(transform.position);
float velocityY = Transform.inverseTransformDirection(velocity).y;
Rigidbody.AddForce(velocityY * YdragCoeff);

this will apply a linear drag on the local Y axis based on linear speed. For a more realistic aprouch velocity should be squared.

Gabo, I think that there is an error in the fact that you ue AddForce with a float instead of with a Vector3, and the sign is not negative, but the idea is clear anyway, thanks.

This is really perfect, thanks! I will change this code to my needs.