How To Create Security Cameras For Your Game
Games like Bioshock, Zelda: BOTW, Deus Ex: Mankind Divided, and many others have all used security cameras in some form or another. Some game object be it a robot, turret, or plain old security camera is used to detect the player and push for stealthy gameplay. Usually, the player is encouraged to avoid, destroy, or even sneak up and take control of them in some form or another. If you’ve played any of these games, then you probably know for yourself the different variations of use that they implemented these mechanics for.
To create something like this, you will need to start by creating a new object or something comparable. For prototyping/testing purposes you can just use a simple Cube and Sphere that is reshaped together so as to have a discernable front and back.
Now add a collider to your new object and adjust the collider’s position to encompass the area that your security camera can see. Make sure this collider is set as a trigger.
Next, you can animate the rotation of the camera object. This is quite simple to do. Just open up the “Animation” window in Unity and while your game object is selected, hit the “Create” button as seen in the example below.
After you create your animation you will be able to customize it within the animation window. Make sure that the “Animator” component was added to your desired game object. If not, add it and attach the new “Animator Controller” that was just created to the game object’s “Animator Component”.
Make sure that you uncheck “Loop Time” for this animation from within the inspector.
Now hit the “Record” button in the Animation window and set your first keyframe by adjusting the object's rotation. This will be your camera’s starting rotation.
Next, move the “Keyframe Marker” to the time in the animation window that you want the camera to reach the end of its rotation. Then adjust your camera’s rotation to the position that you want it to end on and then stop the recording.
Now go into your object's “Animator Controller” and duplicate the animation. Then make a transition to and from this duplication and set the duplicate's speed to “-1" so that it plays backward.
By adding an “OnTriggerEnter” method to a script attached to this object you will be able to detect the Player and execute whatever effects you want!