- Home /
how to check if rotation is past a point?
Hi I'm Jesse. In my game I have an arm that rotates according to the mouse. I want to check for when my arm is pointing to the left to flip the object it's holding. But with the code i have it's only flipping for a half of the left side (from straight down to left so < 0 and >-90) If the arm is pointing to the left the arms rotation is in negative and right is positive. The code I have for this: Code on the rotation arm:
//for rotating arm to look at mouse Vector3 pozycja = Camera.main.ScreenToWorldPoint (Input.mousePosition); float AngleRad = Mathf.Atan2(pozycja.y - transform.position.y, pozycja.x - transform.position.x); float AngleDeg = (180 / Mathf.PI) * AngleRad; this.transform.rotation = Quaternion.Euler(0, 0, AngleDeg + 90); //to check if needs flip if (this.transform.rotation.z < 0 && !isFlipped || this.transform.rotation.z > 0 && isFlipped) { if (this.transform.rotation.z > 170) { isFlipped = !isFlipped; } Debug.Log ("flip"); flipding.SendMessage ("Flippp"); isFlipped = !isFlipped; }
Code that recieves the sendmessage:
public void Flippp () { Vector3 scale = transform.localScale; scale.x *= -1; transform.localScale = scale; }
Answer by HaMrDev · May 03, 2020 at 05:36 PM
i need help with this too i am trying to see if my motorcycle has flipped so i can start my endgame function but when i start the game it calls the function immediately Here's my script
public Transform transform;
public float rotation;
protected GameManager gamemanager;
private void Start()
{
gamemanager = FindObjectOfType<GameManager>();
}
public void Update()
{
if (transform.rotation.eulerAngles.x > 50)
{
gamemanager.EndGame();
}
if (transform.rotation.eulerAngles.x < 0)
{
gamemanager.EndGame();
}
}