how to know when rotation is completed ? 2d

hi i’m making a simple 2d soloar system game, and i want to increment days each time earth does one rotation around itself ( note that it’s also orbiting the star) . now i tried checking the z rotation, if it’s in a certain range then i do my thing, but since it’s in the update function, if earth makes one rotation, days don’t increment by one each rotation. so i’m wondering if there is a certain method that i can use to check the rotation ? here is a picture :

So days don’t increment when the earth is rotating and therefore the script doesen’t work? If thats the case, it is probably because you are checking the number with the “==” operator, and you are rotating every frame with a decimal angle (or it is being mutiplied by “Time.deltaTime”). That makes the rotation not likely to stay in integers, and, if you are checking the value with an integer value, not to return true.
There are different solutions to this, hope it helps.

Rotation around the sun or around it self?
if around the sun than you should probably check position to find if it made full circle.

[Disclaimer: Beginner and not a native speaker]

I have tried it myself and came up a solution, but i dont know if you will like it :slight_smile:

I have a sprite that rotates with the following script: “transform.eulerAngles += new Vector3(0, 0, 5);”

then i made two empty objects as childs of the earth and gave them the names “rota” and “stay”.

I gave both a little box container (as trigger) and a rigidbody with continous collision detection (because they are small and fast).

I tagged “rota” as “rota” and gave “stay” the following script:

(Ignore the UI elements, i used them to count the rotations)

**
public class checkDayPassage : MonoBehaviour
{
public int rotations = 0;
public Text txt;

void Update()
{
    transform.eulerAngles += new Vector3(0, 0, -5); 
    txt.text = "Rotations: " + rotations;
}

private void OnTriggerEnter2D(Collider2D collision)
{
    if (collision.tag == "rota")
    {
        rotations++;
    }
}

}
**

What happens?
The earth rotates. “Stay” rotates in the opposite direction to compensate the movement and stay at its place, and checks if “rota” passes by. “Rota”, as child of earth just rotates like earth. If the childs touch each other they increment the value of the rotations.

Hope this helps in some way :slight_smile:

You should use (Mathf.RoundToInt(rotation.z)) == 360 to check.