- Home /
Calculate Pitch (-90 to 90) from Euler Angles
I have some trouble converting euler angles to pitch angles for aviation that ranges from -90 (pointing to -Y) and 90 (pointing to +Y). Therefore if exceeding those bounds the final pitch should be substracted again. I have made a sketch to visualize what I want to achieve (grey angles):
I have this code for pitch, but it goes only from 0 to 90.
pitch = Vector3.Angle(new Vector3(transform.forward.x, 0, transform.forward.z), transform.forward );
Answer by Bunny83 · Nov 29, 2019 at 04:46 AM
To get the pitch angle all you need is this:
float pitch = Mathf.Asin(transform.forward.y) * Mathf.Rad2Deg;
Thanks, forget to mention that I use 5.6.0.f so this isnt in the API, but I solved it just using transform.forward.y * 90f;
- This will give also the correct pitch angle. Thanks anyways guys.
No, this will not give you the correct angle. It gives a distorted value. The only correct values would be 0, 90 and -90. All other values are more and more off the further you are between those values. The methods I used certainly exist in Unity 5 since they exist since Unity 1.
However I have miscapitalized the Asin method. I just did my usual CamelCase casing. It's the "arcus sine" which is usually written as "arcsin" or with CamelCase as "ArcSin". Since Unity shorten the "arc" to just "a" they made the "s" small so it's actually called "Asin".
I will fix my answer.
Here's how the difference look like:
Ah, now that makes sense. Thank you again for clarifying! :D
Your answer
Follow this Question
Related Questions
rotation to axis conversion problem? 1 Answer
Mathf.Clamp acts strange when going below 0 1 Answer
Rotating on a plane 2 Answers
how to know if an axis has been full rotated? 1 Answer
Problem rotating -90 degrees from default rotation. 0 Answers