- Home /
problem after rotate an object
hello guys, what i actually have is this
private IEnumerator Rotate(
float in_deltatime,
int id,
float duration,
EInputState in_secondState)
{
Vector3 rot = _players[id].transform.rotation.eulerAngles;
float endRotation = rot.x + 360.0f;
float t = 0.0f;
while ( t < duration )
{
if ( _stopRotation[id] == true )
{
yield break;
}
t += in_deltatime / duration;
float angle = Mathf.Lerp(rot.x,endRotation,t);
Vector3 fixedRot = new Vector3 (-angle,rot.y,rot.z );
_players[id].transform.rotation = Quaternion.Euler( fixedRot );
yield return null;
}
}
after it complete a 360 degrees rotation will return to -180, but sometimes is stopping firstly to -180, but sometimes is going to jumpt from -180 to something like 140 degrees.. everything after the while loop... how i can should fix fix it? any idea?
Answer by SunnyChow · Dec 06, 2018 at 08:18 AM
the gameobject's euler angle is converted from its Quaternion rotation, so it always go weird after some rotation. One method is to hold a Vector3 value for the angle and always use it to do rotation. Another method is to directly use Quaternion to do rotation.
Your answer
![](https://koobas.hobune.stream/wayback/20220612183346im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
problem after rotate an object 0 Answers
Flip over an object (smooth transition) 3 Answers
Why the player is not rotating and moving at the same time ? 0 Answers
How can I make it so cameraCenter Roatates 90 degrees smoohly after swipe! 1 Answer
Objects not rotating right half the time based on another object 0 Answers