- Home /
Question by
ARRAYEWHY · Apr 12, 2014 at 11:03 AM ·
rotationaxiseulerangles
Problem rotating -90 degrees from default rotation.
I'm trying to replicate the rotation the guys did in FEZ but rotating -90 degrees from rotation 0 makes the object spin out of control in my current setup since Unity doesn't add on to rotations past 360 degrees but instead resets them to 0. I tried to compensate for the excess spinning but that only looked good on paper. Rotations of positive values work fine though. Any ideas on how to fix this or other setups?
private float rotationValue;
private bool rotating = false;
void Update ()
{
Debug.Log (rotationValue);
Debug.Log (rotating);
if (Input.GetButtonDown ("Horizontal") && rotating == false)
{
rotating = true;
if (Input.GetAxis ("Horizontal") > 0)
rotationValue = transform.eulerAngles.y + 90;
else if (Input.GetAxis ("Horizontal") < 0)
rotationValue = transform.eulerAngles.y - 90;
}
if (rotating == true)
Rotate ();
}
void Rotate ()
{
float rotationGap = transform.eulerAngles.y - rotationValue;
// if (Mathf.Sign (rotationValue) < 0)
// rotationGap -= 360;
transform.Rotate (new Vector3 (0, -(rotationGap) * Time.deltaTime * 14f, 0));
if (Mathf.Abs (transform.eulerAngles.y - rotationValue) < .1f)
{
Vector3 tempRotation = transform.eulerAngles;
tempRotation.y = Mathf.Round (transform.eulerAngles.y);
transform.eulerAngles = tempRotation;
rotating = false;
rotationValue = 0;
}
}
Comment
Your answer
Follow this Question
Related Questions
Rotating Object on its Local World Axis 4 Answers
how to get the absolute direction? 1 Answer
Mathf.Clamp acts strange when going below 0 1 Answer
Calculate Pitch (-90 to 90) from Euler Angles 2 Answers
Rotating on a plane 2 Answers