Comments and answers for "Changing rigidbody drag based on deviation of rigidbody heading to its direction"
http://answers.unity.com/questions/18896/changing-rigidbody-drag-based-on-deviation-of-rigi.html
The latest comments and answers for the question "Changing rigidbody drag based on deviation of rigidbody heading to its direction"Comment by AndrewS 1 on AndrewS 1's answer
http://answers.unity.com/comments/82000/view.html
Thanks for answering your own question for us. I'm just starting out with Unity and I want to simulate aeroplane behaviour with the physics engine. I gather from your posts that the drag of an object is constant (ie entirely independent from the object's shape, orientation, velocity etc). Is this correct?Mon, 06 Sep 2010 04:51:54 GMTAndrewS 1Answer by Ryder
http://answers.unity.com/answers/19021/view.html
<p>Ok, here is the answer... Thanks to Flynn in forums for the assist!</p>
<p>All you need is to get the degress of deviation from the oriention of the object to its velocity...</p>
<pre><code>var dif = Vector3.Angle(rigidbody.velocity,transform.up);
</code></pre>
<p>(This assumes that forward is in a positive Y direction in the rigidbody's local space)</p>
<p>once you have the deviation in degrees, you can perform any math on it to get a new drag value.</p>Tue, 08 Jun 2010 06:31:51 GMTRyderComment by Ryder
http://answers.unity.com/comments/73964/view.html
Maybe I should break this down... it may help.
I think that either I need TWO ROTATIONS or TWO VECTORS which represent the direction of travel of the object, and then the heading of the object.
How does one access the direction component of a vector? (by normalizing it?) But then it's confusing again, because the "heading" of the object is a quaternion... and I don't know how to convert that to a normalized vector. But once I have both (expressed as a pair of rotations, or a pair of vectors), there are functions to get the delta angle out.
So confused...Sun, 06 Jun 2010 22:41:51 GMTRyderComment by Ryder on Ryder's answer
http://answers.unity.com/comments/73962/view.html
Thanks SpikeX, this looks pretty good to me, although I can't see where the actual direction of the body is taken into account... (rigidbody.velocity) I see the object heading in the transform, so that is half of it.
I think we still need to divine two vector "directions" (the transform and the velocity) and compare them in a euler form (the degrees of separation) between the two vectors. Once we have degrees between the two, the rest is trivial.Sun, 06 Jun 2010 22:10:57 GMTRyderAnswer by qJake
http://answers.unity.com/answers/18911/view.html
<p>You'd probably want to do something like this:</p>
<pre><code>// Set this to be the "maximum drag", i.e. when
// the object is facing the wrong direction completely (rotation 180).
float maxDrag = 1;<br />
// 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;<br />
// Calculate ratio
float drag = (offsetAngle / 180) * maxDrag;<br />
// Set drag here
rigidbody.drag = drag;</code></pre>Sun, 06 Jun 2010 20:34:23 GMTqJake