- Home /
transform.Rotate on Z axis moves the entire object instead of rotating in place
I'm following an old tutorial of brackeys on how to make a game like color switch(link here:https://www.youtube.com/watch?v=gE7gc1sblUA), and I'm trying to make a circle that spins in place. This is what it looks like:
I added the same script used in the tutorial to the parent object, which is this : using UnityEngine;
public class Rotator : MonoBehaviour
{
public float speed = 100f;
void Update()
{
transform.Rotate(0f, 0f, speed * Time.deltaTime);
}
}
The problem is, instead of making the circle rotate in place, the circle rotates around the center point of the parent object. If anyone can tell me what Im doing wrong here it'll be really appreciated.
P.S for what it's worth im using Unity verison 2019.1.8f1
Answer by unity_ek98vnTRplGj8Q · Mar 19, 2020 at 04:12 PM
Yea, calling transform.rotate will rotate the transform about its local origin. Is there a reason that your parent object's center is not the center of the 4 circle pieces? If you move your child objects so that their center aligns with the parent transform then your script should work as intended. Generally speaking, unless you are offsetting for a particular reason then you should have your parent transform align with the children transforms.
I arranged the pieces around the center of the parent and it works now, I didn't think the position will matter and the script will work anyway, thank you for your help ^^
Your answer
Follow this Question
Related Questions
I am making a 2d game and I want to make it where to can pick up bricks with your mouse 3 Answers
Boxcollider2d sinks into Ground when falling on a non straight surface 0 Answers
Z order for GameObject 0 Answers
Trouble with tilemaps as prefabs for 2D plattformer 1 Answer
How does Unity decide to render some objects over others? (2D) 0 Answers