How Do I Rotate An Image Equally Around A Circle?

Hi, I have a player image that rotates around a central point. That part of the code works fantastic. If I had a sphere that had to rotate then life would be grand (so positioning is not an issue).

I have a bird that I need to rotate around the ‘circle’ and I’m not sure how to rotate it equally every frame so that after a complete circle the animation will start again.

The code below is what I use for positioning, however after a while you can see the image start turning into the center, like it is turning the image more than it should, so left long enough the image would be turning on itself:

``````    float circleDiameter = 4.0f;
float timeCounter = 0;

timeCounter += Time.deltaTime;

float x = Mathf.Cos (timeCounter) * circleDiameter;
float y = Mathf.Sin (timeCounter) * circleDiameter;
float z = 0;
float GullRotatedValue = 360;
float rotationIncrement = 1;
transform.position = new Vector3 (x, y, z);
``````

The first revolution looks ok, but then the bird starts rotating more than it should and starts pointing towards the center of the circle instead of continuing to fly around it. Here is the code for rotating:

``````    if (GullRotatedValue < 0) {
GullRotatedValue = 359f;
} else {
GullRotatedValue = GullRotatedValue - rotationIncrement;
}

PlayerGull.transform.rotation = Quaternion.Euler(transform.rotation.x, transform.rotation.y, GullRotatedValue);
``````

This is the first app I have worked on and am far from proficient in Unity, so any pointers would be welcomed. I did look for other existing answers, but couldn’t find a good fit for my question.

If the code needs a correction, or if there is a better way to achieve this then I am happy to learn.

Thanks.

Can’t test partial code, but looking over it. This sections doesn’t look right:

`````` if (GullRotatedValue < 0) {
GullRotatedValue = 359f;
} else {
GullRotatedValue = GullRotatedValue - rotationIncrement;
}
``````

the value is getting set to 359 when it’s below 0, but what happens if the value was -5 before the if-statement? Shouldn’t the next value be something like 354 instead of 359?

Basically, take in account the remainder value when resetting. Maybe this will work:

``````GullRotatedValue -= rotationIncrement;
if (GullRotatedValue < 0f) {
GullRotatedValue += 360f;
}
``````

An even simpler way is to parent the bird to a GameObject and rotate the parent.

``````public class RotateTest : MonoBehaviour {

public float speed = 10f;

// Update is called once per frame
void Update () {
transform.Rotate(Vector3.forward * Time.deltaTime * speed);
}
}
``````