- Home /
Detect high rotation
I want to detect rotation of my car object so if it's to high I will set it to the ground again. I thought it will be easy. I used if (transform.rotation.eulerAngles.x > 30) { Debug.Log("Too high!"); } } to see if it works. And Debug Log is triggered even with rotation 0. Why is that?
Answer by Marceta · Nov 17, 2016 at 06:33 AM
Is that object child of some other object? If it is then use localRotation instead of rotation. Also you can add another check if rotation is not equal to zero.
using UnityEngine; using System.Collections;
public class test : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
// if (transform.localRotation.eulerAngles.x > 30 && transform.localRotation.eulerAngles.x != 0)
if (transform.localRotation.eulerAngles.x > 30) {
Debug.Log ("Rotation X to high!");
}
}
}
It's still the same. With local and global roatation and also with !=0 Debug is triggered. Script is attached to the parent object of car that is the highest in the hierarchy.
Ok I know what is the issue. I used: Debug Debug.Log(transform.eulerAngles.x)
and I found out that my x is 356 with is strange but I will try to work around that. Thanks for help!