Setting Up the Security Cameras

Adding Rotating Animation and sensors to detect Player

After we get past the Guards, it is time to set up our next obstacle that our Player needs to overcome, the security cameras. To accomplish this we will need to create a new C# script and also create new animation sequence for the Cameras.

Animating the Cameras:

The good thing about animating the rotation only of an game object is that it can be applied to multiple of the same object without consequence. To start, we first need to create an new animation clip, so select the Camera_1 game object and within the Animation window (windows > Animation > Animation) we can start the animation. In the first frame, set the rotation of the Y axis to 45, then at another set interval (ie. 1 second later) set the Y axis to -45. Finally, to make the camera return back to the origin, at another set interval mark the Y axis back to positive 45.

This will make the camera loop back and forth. If the speed of the loop is too fast we can reduce the speed by setting the “Sample Rate” down to either 15 or 10.

The back and forth pan of the Security camera

Adding Detection to the Camera:

Now we need to make the camera be able to detect the player if they cross the line of sight. Provided in the scene are 3D cones that also rotate with the camera. This cone will be our detection device.

The settings for the Camera Cone.

To begin, add an Rigidbody component to the cone and deactivate the gravity setting by unchecking it. In the Mesh Collider make sure that the “Is Trigger” function is turned on.

Create a new script called Security Cameras, and within that script we are going to follow a very similar approach that we have done with the Guards detection ability. We are going to have an void On Enter Trigger event which checks for the Player tag. If the player collides with the object we will trigger an Game Over cutscene of the player getting captured.

To start, make sure that you create a Serialized Field or make the cut scene handle public to gain access to it later. Delete the other unwanted codes (start and Update methods) and add in Void On Enter method. Add a IF statement to check for the player and set the cutscene game object to true.

Back in Unity, drag the new camera script into the 3D cone game object and also drag and drop the captured cutscene.

Darren doing a fantastic job as a spy

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How We Work in GoustoTech — Part 1 — Team Structure

How we migrated to serverless in a weekend?

Confessions of an Ethereum Staker

Choosing the Right Service Discovery Solution in AWS

Bluetooth Low Energy (BLE) Tutorial for Beaglebone using BleuIO

Roll your own RFH2 header for WebSphere MQ

Why I love Excel

Build Oracle Graph on Docker (Part 1/2)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Cleaning up the Homing Missile code

Creating the Main Menu

Using Decals in Unity

Unity new Input System : Tips to create a “clean” Player Input System(Part XI)