I’ve been struggling with this too long now, so I thought it was time to seek help.
I have a dummy object in my scene with 6 child objects spaced evenly around it on the X/Z plane (like planets around the sun). I want to rotate the dummy object clockwise, smoothly over time by 60 degrees (60 * 6 = 360) every time the space bar is pressed. NOTE: I want to continue the rotation behavior for multiple revolutions.
I have the code below that was a reply to a similar post on this forum that I slightly modified. The problem I am having however, is that the rotation starts to behave erratically once a full 360 rotation is reached (spins wildly back and forth). I assume this is has to do with “60” being added to “360” to create an invalid euler angle?
Thanks in advance for any help you can offer!
Unity 5.2
C#
public float smooth = 1f;
private Vector3 targetAngles;
void Update () {
if (Input.GetKeyDown (KeyCode.Space)) {
targetAngles = transform.eulerAngles + 60f * Vector3.up;
print (targetAngles);
}
transform.eulerAngles = Vector3.Lerp (transform.eulerAngles, targetAngles, 10 * smooth * Time.deltaTime);
}