Rotation goes wrong when initialized

Hi there!I’m pretty new to Unity and C# overall and I was watching a tutorial on how to remake the mobile game Color Switch just to get the hang of the things a bit.After getting to the part where the circle keeps rotating, I have used the following code that was working on the video but not for me as I couldn’t realise how I could do that by myself.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rotator : MonoBehaviour
{
    public float speed = 100f;
    void Update()
    {
        transform.Rotate(0, 0, speed * Time.deltaTime);
    }
}

I have applied this to my circle that I have made from 4 separate sprites that each has a collider, and, when I click Play, The whole thing is rotating, not the coloured parts.Basically instead of standing still and the color parts rotating, it rotates as a whole and the angle keeps changing instead of the colors ciclying by rotating correctly on the Z axis.The position does not change even though it seems like it’s moving instead of rotating in one place.The 4 sprites are put together in a game object that has this script.
Could you guys help me with this one?
Is this method deprecated for doing something like this?Or what’s really happening?

Thanks!

Note: If you use code tags rather than the inline code block you get line numbers and syntax highlighting which make it easier to read.

That said, this isn’t a code issue. It may be that this script is being placed on the wrong objects? It’s hard to say from this description - could you post a screenshot of the objects, scene view, etc to better illustrate the desired behavior vs. what you’re seeing?

1 Like

Sure! Here are the screenshots:

Here is how it’s supposed to be staying while the colors would be rotating and the circle staying completely still.5167535--512726--1.png

And this is how it actually rotates.The circle seems that is rotating as a whole in a certain angle instead of standing completely still while rotating on the Z axis.It does full rotations while deviating a bit from actually the initial position.I don’t know why it does this to be honest.
5167535--512729--2.png

Hope this clarifies what I am meaning.Also, you can see on the left the circle colors and the object that they are in.The object has the script.

Sounds like the pivot point of the child objects isn’t centered on the circle? If you select the circle, where is the “move widget” in the scene view? It ought to be in the center of the circle, but I suspect the children are placed in such a way that it’s off center.

1 Like

5167766--512735--3.png [quote=“StarManta, post:4, topic: 765319, username:StarManta”]
Sounds like the pivot point of the child objects isn’t centered on the circle? If you select the circle, where is the “move widget” in the scene view? It ought to be in the center of the circle, but I suspect the children are placed in such a way that it’s off center.
[/quote]

It’s somewhere in the top left, I have tried sort of placing it in the center of the circle before attaching the little parts to the circle game object and is still does the same thing to be honest just a bit less or at least seems like it.

There is a photo that explains it I hope and makes more sense than what I say haha.

It’s probably best to, rather than eyeballing it, type in the numbers of the positions of the child objects. In a setup like that they most likely would all have the same X and Y coordinates, just with different +/- signs. If you do that they’ll probably be centered.

1 Like

I have did that for the circle parts already.But the problem is not gone.Can I do something else with maybe the GameObject itself?
Oh, wait.Two of the circle parts are just the Z rotation put to 180 because I was lazy to make them again.Would that matter?

Edit: Everything has the same X/Y just different +/- signs and I have measured the center of the circle and that is now the position of the GameObject that has the whole circle and now it works!You were absolutely right.Thanks for helping me fix this! :slight_smile:
I do really appreciate it as I find it hard to point at things like this quickly without that much knowledge haha.
Everything is fine now! :smile: