# Changing rigidbody drag based on deviation of rigidbody heading to its direction

Hi all... More physics! (day 2 for me using Unity.. it rocks)

When you throw a dart point first, the drag on it is low. If you throw it with the point 90 degrees to the target it presents a different cross section to the air, and the drag increases.

I need Unity to understand this a little better, so I figured I could change rigidbody.drag based on the difference between heading and direction of movement.

Would I be subtracting Vector3's to get a difference? How then to convert that to simple degrees of deviation?

Conceptually simple... I think :) But in the end, euler degrees deviation is what I am searching for.

Thank you all so much!

Ryder

Ok, here is the answer... Thanks to Flynn in forums for the assist!

All you need is to get the degress of deviation from the oriention of the object to its velocity...

``````var dif = Vector3.Angle(rigidbody.velocity,transform.up);

``````

(This assumes that forward is in a positive Y direction in the rigidbody's local space)

once you have the deviation in degrees, you can perform any math on it to get a new drag value.

You'd probably want to do something like this:

``````// Set this to be the "maximum drag", i.e. when
// the object is facing the wrong direction completely (rotation 180).
float maxDrag = 1;

// Offset angle is how much the object has
// rotated from "zero" in either direction, from 0 to 180.
float offsetAngle = (transform.eulerAngles.y + 180) % 180;

// Calculate ratio
float drag = (offsetAngle / 180) * maxDrag;

// Set drag here
rigidbody.drag = drag;
``````