# Get angle of transform for relative drag

hello

I explain my idea I have a simple character that is falling skydiving style and that you can rotate in his three local axis. (initially his rotation is 0) My intention (more or less) is to apply a strong drag when he’s parallel to the ground (90degree rotation) and a light drag when he’s perpendicular to it (0 or 180degree rotation). So actually i just search a way to tell me his rotation from 0 to 360 on each axis. I used Debug.Log(transform.rotation.eulerAngles) to tell me his angle (on one axis to test) … it goes not bad until 180degree and then it jumps to 360degree and i don’t understand it anymore.
It’s certainly a stupid question but i’m a beginner thanks for the help! (pardon my bad english)

i don’t know what angle your checking, but if your player is looking down its local z-axis (most likely) you should check the player’s world eulerAngles.x value ((transform.rotation.eulerAngles.x). you have to interpret the x angle to determine whether you are considering the player to be perpendicular or parallel. There are grey areas involved if your player is rotating around freely. If so, he will never be exactly perpendicular or parallel see the screenshot.

1 Like

Another approach occurred to me. Take advantage of Unitys physics system:

1. -Assign proper gravity to your scene:
— public static Vector3 DEFAULT_GRAVITY=new Vector3(0, -100.0f, 0);
— Physics.gravity=DEFAULT_GRAVITY;

-Play with the rigidBody’s Drag, AngularDrag, and Mass values in the inspector

3. -Add a box collider or mesh collider to your player. This will probably not work with a sphere collider or capsule collider.

When your player is free falling, the physics system should automatically calculate and apply drag forces to the player based on gravity, mass, drag values, and the rotation of the player.

I have never used this before but it should work. You just have to play around with the gravity, player mass, and drag values till you get something that is realistic.

Hey thanks for the time you took to think about this i appreciate it Actually I already put a rigidbody with gravity etc. on the character and after reading some things about drag I think that I understood that there isn’t automatic calculation of drag related to the shape/aerodynamism of the collider but after re-reading maybe it could be scripted or something. I’m going to get more documentation.

ok. maybe you just need to change the drag through the script based on the x eulerangle.
if facing the ground or up, increase the drag. if not, lower the drag

i have done something similar with window blinds and it worked.

i added mesh collider, and a rigid body.
gravity = new Vector3(0,-1000.0f,0);
window blind mass = 0.01
drag = 1

Rigidbody rb=windowBlind.GetComponent();
rb.velocity=Vector3.zero;
rb.useGravity=true; (allow gravity to swing the window blind)

i tested it out: when the drag is set to zero, the window blind sways infinitely.
with drag set to 1, it only sways a few times before it stops complete.
with no mesh collider, the blind always swing infinitely
so the physics system is getting the mass, gravity, and collider info to adjust the speed over time.

the unity manual says…
drag = How much air resistance affects the object when moving from forces (ie gravity). 0 means no air resistance, and infinity makes the object stop moving immediately.

It’s ok for the drag i know how to use it my main problem was to know the rotation of the character so i found what i was looking for… it’s not “transform.rotation.x” that i had to use but the angle between the transform’s vector3 and the global vector3 because “transform.rotation.x” gave me really strange values. So it’s good I can go on. Thank you a lot!