Unity: Rotate & Rotate Around

Ryan McCoach
3 min readNov 9, 2023

Intro

In this article we are going to discuss how to make an object rotate and rotate around another object.

Rotate

Using transform.Rotate method we can rotate a game object along the 3-axis (X,Y,Z) at a given speed.

We will create a Vector3 variable and give it a serialized field so we can adjust the axis when want to rotate along in the inspector instead of hard coding using Vector.Up/Down/Left/Right/Forward/Back. The second variable will be a float that will determine the rotation speed along that axis.

Using normalized values (0–1) assigned to the axis will determine the rotation on that axis.

  • Negative value = rotate counter clockwise
  • Zero value = no rotation
  • Positive value = rotate clockwise

Looking at the image above you can see how change the axis values effects the rotation of the object.

Rotate Around

When you want a game object to rotate around another game object Unity has a method transform.RotateAround().

The method will need a Vector 3 which determines the axis of the object to rotate around that the object will move around. A float which controls the speed of the rotation around speed and a game object that will be the object that you want to rotate around. Give these variables serialized field attribute so we can adjust these avlues in the inspector.

Pass in the target’s position, then the rotation axis and lastly the speed.

Just like rotation, putting in a negative and positive values determine the direction of the rotation and you will need to assign the game object you want to rotate around.

Look at the image above to see how the values effect the rotation around another game object.

--

--