- Home /
Get rotation direction and total angle?
Hi, how to count total rotation angle and direction? In my case it's a steering wheel. Thank you!
Answer by Glurth · Jun 14, 2017 at 04:05 PM
The transform component of every scene object has a member called "rotation". This is in the form of a quaternion, but you can convert if to degrees of rotation around each axis using the eulerAngles member. https://docs.unity3d.com/ScriptReference/Quaternion-eulerAngles.html
You can also get the direction the transform's rotation is pointing using transform.forward. https://docs.unity3d.com/ScriptReference/Transform-forward.html
You can compute the total angle between the world's "forward direction" and the transform's forward direction using the Vector3.Angle function. https://docs.unity3d.com/ScriptReference/Vector3.Angle.html
But this steering wheel will be attached to car, which will be moving , so I guess it's not gonna work.
Any way this is my current code, but it's only collet from -180 to 180 degrees... But I need register more than 360 angle
public float SteeringWheelAngle;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
SteeringWheelAngle = transform.eulerAngles.y;
SteeringWheelAngle = (SteeringWheelAngle > 180) ? SteeringWheelAngle - 360 : SteeringWheelAngle;
}
Sounds like you want to use the localRotation member, rather than the rotation member. This will get the rotation relative to the parent. (Assu$$anonymous$$g the steering wheel is a child of the carBody, and that it is the carBody, that actually changes position.)
transform.loclRotation.eulerAngles
But how can I register that weel has been steered left for 720 degrees for example?
Your answer
![](https://koobas.hobune.stream/wayback/20220612124155im_/https://answers.unity.com/themes/thub/images/avi.jpg)