Day 71 — Interacting With the Sleeping Guard.

Hey and welcome!

I say interacting but in reality what’s going to be happening here is that once the player gets close enough to the sleeping guard they’ll pass into a trigger that will play our cutscene that we made for the key grab.

If you click into the Level_Colliders object you’ll find Grab_Cut_Scene_Zone which is the outline you’re seeing above. Go ahead and set the Trigger to true in the box collider component and then add a Rigidbody with the gravity turned off.

Now create a script called GrabKeyCard or similar and add in the following code:

public GameObject keyGrabCutscene;

You should be good and familiar with this code now, make sure to remember to drag in your cutscene into the keyGrabCutscene value in the GrabKeyCard script component that you’ll want to add to your Grab_Cut_Scene_Zone object.

When testing out the code you may notice a distinct problem with the cutscene and that’s the fact that Darren the player is controlling and the sleeping guard object are still visible in the cutscene.

To fix that, open up the timeline for your sleeping guard cutscene and then add in two activation tracks where you can add the player object and the sleeping guard object to. With those done you’ll need to shorten the track to the last frame of the timeline, either manually or through the inspector:

Doing that will mean that the objects will not be active during the duration of the cutscene and will pop back in right at the end when it’s time to start playing again.

Now there’s one more problem that remains and that’s the fact that when the cutscene ends it doesn’t take the player back into the action. To start fixing that go ahead and edit the fade to black at the end so that it only goes up to the frame before the last one. Hit the record button for you track handling the fade to black and set its start frame to 357 and the end frame to 360 and then bring it’s alpha value right down to zero so that the screen is no longer black.

This gives the view of the game back to the player but you’ll find that the camera is in the wrong place. To fix this you’ll need to add a new cinemachine shot between frames 357 and 360 again.

Now create a new virtual camera and attach it to your new cinemachine shot by using the inspector and then position your camera like this or similar:

Doing all this will give the control back to the player but you’ll notice that the actors are still visible on the screen and Darren’s movement is a little bit off. We’ll need to add in one last activation track before we’re home free. In this track you’re going to add in the parent of your cutscene object, if you don’t have one already then create an empty game object, stick your cutscene object in that and then drag and drop it to the track.

Set this track to last from fram 0 all the way to frame 359 since this is technically our whole cutscene here so we want it to be active for the full length. Now click on your cutscene object in the hierarchy and you’ll see a Playable Director component, change the wrap mode to Hold if it isn’t already set to that.

At this point you should be home free and have something similar to the above, this is pretty exciting knowing how to slot in a cutscene now!



Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

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
Connor Fullarton

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.