This thing is driving me crazy atm, this might be the side effect of 9 hours coding, or i reached my capacities, but to not f*ck up my deadlines i cant waste more time on this alone so i need to ask you guys.
So i want to rotate this GameObject which contains several meshes together, around the Z axis (Local) around the GameObject Center, but i cant seem to find out how Please help me
Should be pretty simple. Next time google ‘rotate object unity’ first. But here’s the code anyway.
public float speed = 5; //Five degrees per second
void Update()
{
transform.Rotate(Vector3.forward * Time.deltaTime * speed);
}
Vector3.forward is basically (0,0,1) so it rotates along the z axis.
If you want to choose the axis like in the example you can use the following:
public float speed = 5; //Five degrees per second
[Tooltip("Set any of the x, y, or z values to anything above 0 to rotate "+
"along that axis, and multiply the number you inputted by speed " +
"to get the rotation speed in degrees per second!")]
public Vector3 RotateVector = new Vector3(0,0,1);
void Update()
{
transform.Rotate(Vector3.forward * Time.deltaTime * speed);
}
You should child all the meshes to a single empty game object previously aligned to the axes you want, and then rotate it with Rotate: Rotate defaults to local space, thus the object and all its children will rotate about its local axes as expected.