- Home /
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
$$anonymous$$aybe 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...
Answer by Ryder · Jun 08, 2010 at 06:31 AM
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.
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?
Answer by qJake · Jun 06, 2010 at 08:34 PM
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;
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613053624im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
drag object including free rotation 0 Answers
Is there any way to apply drag to a 3d rigidbody in only 1 direction? 2 Answers
Touch controlled ice puck 0 Answers
Drag a rigidbody2D around scene 2 Answers
Add force based on drag speed 4 Answers