How to build a XZ only rigidbody drag function in local space?

Hi Guys,

I need to build my own rigidbody drag function because it must be splitted on XZ and Y to achieve a breaking function for my avatar that not infacts the drag on the Y axis.

Here in the Answers forum I found a solution. But it is only usable for global space.

Vector3 vel;
vel = rigidbody.velocity;
vel.x *= 1.0f - dragXZ; // reduce x component…
vel.z *= 1.0f - dragXZ; // and z component each cycle
rigidbody.velocity = vel;

Do someone have a clue how to make a own drag function that works for local space?

Thanks to aldonalettos Answer in another thread I managed it by “my own”. Sorry for posting my question to early.

float dragXZ; // drag value (1 is stop and 0 is no drag)
Vector3 vel;
Vector3 locVel;

locVel = transform.InverseTransformDirection(rigidbody.velocity);
locVel.x *= 1.0f - dragXZ;
locVel.z *= 1.0f - dragXZ;
rigidbody.velocity = transform.TransformDirection(locVel);

Thank you guys!