How to calculate the tilt angle of an object?
Hi,
I have the following problem: I want to draw a horizon-line on the UI for my plane that shows the current tilt compared to the ground plane. For that I need the tilt angle of my plane.
First I tried to calculate the angle between this.transform.right and Vector3.right but as the plane moves around all axis (and the Vector3.right always stays the same) that only works when the plane is flying in one direction:
float lineAngle = Vector3.Angle(this.transform.right,Vector3.right);
Vector3 polar = Vector3.Cross(this.transform.right, Vector3.right);
if (polar.z < 0) lineAngle = -lineAngle;
horizont.transform.eulerAngles = new Vector3(0, 0,lineAngle);
How can I do that correctly?
Comment
Your answer
Follow this Question
Related Questions
On which side of the vector on graph is the origin? [Geometry] 1 Answer
Attempting to apply force to object, paralell to mouse drag. 2 Answers
How to get vector rotated by specyfic angle? 0 Answers
How to detect the tilt angle of the mobile device on start? 0 Answers
Calculating Relative angles 1 Answer