Rotating security cameras in Unity

Daniel Kirwan
2 min readJul 6, 2021

Objective: Rotate some in game security cameras using animations

Now that I have set up my security cameras, I need to rotate them so that has a harder time trying to avoid them.

With the gameobject that you would like to animate selected in the hierarchy, open the animation window and create a new animation. This will create add an animator component to the game object. I have two cameras that will be operating in the same manner so once one animator component is made, I then copied the copy and then pasted as new in the 2nd camera.

Now that the animator component has been added, it is now time to animate the cameras. This is the simple part.

In the animation window with the gameobject selected, click the record button. I am changing the rotation in the Y-axis to 45 and then after 1 second I am changing that to -45. I now click the record button again to stop the process. The animation will now slowly move between our two frames smoothly.

Now it’s time to set up the controller for the animation. To quickly open the animator window, click the game object and double click the controller on the animator component.

There should be 1 animation in the controller already and it should be the default animation. Click the animation and make sure that the speed is set to 1. Then make a copy of the animation and set its speed to -1, this will reverse the animation. This is a quick way for an animation to be reversed.
Now make transitions from the default animation to the copy and back again.

That should be enough now for the camera to play the initial animation and then once it has reached the end, it will then move to the second animation and because the speed is set to -1 it will play the animation in reverse.

--

--