- Home /
Question by
icxrusluv · Apr 21 at 09:06 AM ·
c#rotationeuleranglesrotatearound
RotateAround reversing doesn't work with negative vector3
Hello, I have some code that is supposed to rotate an ui elements parent (empty gameobject). The rotation works great in one direction and switching to the other directions works as well, but then it gets stuck on one direction. I know it is because the EulerAngles don't recognize negative numbers, but I am unsure how to fix this. I looked through every similiar question on Google, but none fixed the issue.
How do I get the object to switch direction when it hits -70 rotation?
public GameObject target;
public int speed = 40;
public bool ChangeDirection = false;
public Vector3 leftRotation = new Vector3(0, 0, 70);
public Vector3 rightRotation = new Vector3(0, 0, -70);
void Update()
{
if (!ChangeDirection)
{
//Check for direction change
if (this.transform.rotation.eulerAngles.z > leftRotation.z)
{
ChangeDirection = true;
}
//Rotate
this.transform.RotateAround(target.transform.position, Vector3.forward, speed * Time.deltaTime);
}
else if (ChangeDirection)
{
//Check for direction change
if (this.transform.rotation.eulerAngles.z < rightRotation.z) //Issue
{
ChangeDirection = false;
}
//Rotate
this.transform.RotateAround(target.transform.position, Vector3.back, speed * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Limit Rotation Issues 1 Answer
Multiple Cars not working 1 Answer
Rotation Problem - Simulating Gimbal lock 1 Answer
How to rotate an object around another facing to mouse? 1 Answer