My journey becoming a Unity game developer: Security Cameras-Animate security cameras

Rhett Haynes
3 min readNov 11, 2021

--

Objective: Animate the security cameras to patrol the area.

Security cameras rotating back and forth to patrol the area.

Start by adding an Animator component to the Camera_1 game object inside of its Parent Camera container game object under the Security Cameras game object. Then open the Animation tab from the main menu using Window->Animation->Animation. Click on the Create button inside of the dopesheet, and create a new animation file name Camera Rotate inside of the Animations folder within a new folder name Cameras.

Created an Animation file and controller for the security camera.

Once that’s done, click on the REC button in the Animation menu. Create the 1st keyframe to start the rotation by changing the Y-axis value to 45 degrees. Drag the timeline to the one second mark, and create the end rotate position on the Y-axis to -45 degrees. Also, in the Assets folder select the Cameras folder inside of the Animations folder and select the Camera Rotate anim animation clip. Turn off the Loop Time setting to prevent the security camera from looping the animation clip over and over. Press Play in the Animation menu, and watch the security camera rotate from one side to the other.

Setup the security camera’s animation.

The camera’s animation plays and it’s not looping, but it’s moving too quick from one end to the other.

Security camera animating with Loop Time turned off.

With the Camera_1 game object still selected, go back into the dopesheet and in the Samples box change the value from 60 to 15. This will expand the animation’s play time from 1 second to 3 seconds. Press Play and notice the camera’s rotation is now slower than before.

Changed the animation’s speed using the Samples setting.

Next, we want to make the security camera animate back and forth to patrol the area. Open the Animator tab by double-clicking on the Camera_1 controller in the Controller slot in the Animator component.

Select the Camera Rotate anim state, right-click and choose Copy. In an open area, right-click and choose Paste to create another Camera Rotate anim state. Rename this state to Camera Rotate Reverse as this state will rotate in reverse to its original starting position.

We’re going to leave the anim to Reverse state’s transition Speed to 1, as this will make the animation move in a forward direction. However, we will click on the Reverse to anim transition and change the Speed to -1, as this will make the animation move in a reverse direction.

Created another animation clip to make the security camera go back and forth.

One last thing is we will make the other security camera animate as well. Select Camera_1 in the other Camera game object, and add an Animator component to it. Drag the Camera_1 controller from the Animations folder into the Controller slot in the Animator component. Press Play to watch both security cameras rotating back and forth simultaneously. If you want the cameras to rotate from different starting and ending positions, we will need to create another Animation Controller and animation clip with different rotation values for the Y-axis.

Both cameras rotating back and forth together.

Next time we will work on detecting Darren with the security cameras.

--

--

Rhett Haynes
Rhett Haynes

Written by Rhett Haynes

Learning to become a Unity game developer.

No responses yet