Hi All,
I’ve been looking around for a while and can’t find any definitive answer for how to rotate in a certain direction. So I’ve done a bit of testing and exploring different ways to make this work.
In this example, the currentRotation is 0, so the rotation goes clockwise to -90. Which is great.
public Vector3 currentRotation;
while (true)
{
currentRotation.y = Mathf.Lerp(currentRotation.y, -90, Time.deltaTime);
transform.eulerAngles = currentRotation;
yield return null;
}
Though when I do this afterwards, once the currentRotation is now -90 and I want to go back to 0 it takes the long way round, so goes all the way down to -359 then onto 0.
public Vector3 currentRotation;
while (true)
{
currentRotation.y = Mathf.Lerp(currentRotation.y, 0, Time.deltaTime);
transform.eulerAngles = currentRotation;
yield return null;
}
Now my solution is to try and use rotateAround with a Vector3 direction such as:
transform.RotateAround(transform.position, Vector3.down, Time.deltaTime);
This allows me to choose the direction. The issue here now is I can’t get the rotation to stop, considering I want to go to -90 how do I make this stop? As doing something like this doesn’t work, as it’s a negative value:
while (transform.localEulerAngles.y > -90)
{
transform.RotateAround(transform.position, Vector3.down, Time.deltaTime);
yield return null;
}
I hope this all makes sense and someone can possibly help with a solution somewhere! Going to try different rotation methods to see if the direction works differently. Some people say Lerp takes the quickest route always, but this can’t be true otherwise my rotation wouldn’t take the long way round to go from -90 to 0.