My journey becoming a Unity game developer: Sleeping Guard Interaction-Player NavMesh movement fixed

Rhett Haynes
4 min readNov 18, 2021

--

Objective: Fix the player’s movement along the NavMesh after the cutscene plays. Also, remove the guard’s security card from the game view after the cutscene is over.

Cutscene plays, then Main Camera is back in position allowing the player to walk on the NavMesh properly.

We were able to fix the Main Camera’s position after the Sleeping Guard Cutscene plays, but a new problem came up when the game picked up from where we left off activating the cutscene. The player doesn’t follow the click-n-point system anymore. Instead, the player goes in different directions after every click. This is happening because the CM Final Shot virtual camera took over the position of the Main Camera, therefore the rays from the Main Camera aiming where the the player clicks are not being recognized.

Sleeping Guard Cutscene plays, but the player doesn’t follow directions properly.

Let’s begin by going back into the Timeline editor of the Sleeping Guard Cutscene. In the Main Camera’s Activation Track, adjust the CM Mid Shot clip’s End Clip Timing down 3 frames from the end of the duration. Then select the CM Final Shot clip, attach it to CM Mid Shot, and adjust its frame duration to be 2 frames after the CM Mid Shot End clip. This will give us a little time to see if the Main Camera is back in its proper position.

Mid Shot and Final shot virtual cameras duration adjusted to allow us to see if the Main Camera takes over.

Now to deactivate the virtual camera that’s preventing us from playing the game properly, we’re going to create another new Activation Track. We have a little problem in that the CM Final Shot virtual camera is located within the Sleeping Guard Cutscene itself, therefore if we deactivate it directly we will go back to our previous problem plus this problem still being active.

Instead, we’re going to add the Cutscenes game object that is holding all of the cutscenes with this virtual camera as well into the Activation Track’s slot. Click on the clip, and change the End Clip Timing to be one frame before the end of its duration. This will turn off the virtual cameras used in the cutscenes from being able to take over the Main Camera’s position.

Sleeping Guard Cutscene with its virtual camera deactivated through the Animation Track.

Make sure to turn off the Sleeping Guard Cutscene game object so the game can play properly.

Turn off the Sleeping Guard Cutscene game object.

When we play the game, we will see the cutscene play when the player comes to the guard’s desk. The game’s characters will reappear with the Main Camera back in its proper position, and the player is now under the control of the Main Camera with the click-n-point system back in effect.

Cutscene plays and the player is back under the control of the Main Camera.

One other thing that is bothering us is that when the cutscene finishes playing with Darren stealing the card off the guard, we will see the card reappear on the guard after the cutscene. This is because the cutscene’s guard and the game’s guard are 2 different game objects in play. The cutscene’s card is removed through the Timeline editor, but the game’s card is still active inside of the Sleeping Guard game object.

To fix this let’s open the GrabKeycardActivate script, and create a new Type Game Object variable which will hold the Sleeping Guard’s Card game object and name it sleepingGuardCard. Inside the OnTriggerEnter() function, create another IF statement to check if the Sleeping Guard Cutscene is active in the Hierarchy. If it is, set the sleepingGuardCard to be not Active.

Deactivate the security card when the cutscene is active.

Play the game once more, and see the card disappear in the cutscene when Darren grabs it. Then when the cutscene finishes, notice the card is no longer on the guard’s waist.

Security card deactivated when the cutscene plays.

Now that we have finished with the Sleeping Security Guard interaction part of the game, next we will work on the Game Manager.

--

--

Rhett Haynes
Rhett Haynes

Written by Rhett Haynes

Learning to become a Unity game developer.

No responses yet