My journey becoming a Unity game developer: Sleeping Guard Interaction-Player NavMesh movement fixed
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.
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.
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.
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.
Make sure to turn off the Sleeping Guard Cutscene game object so the game can play properly.
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.
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.
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.
Now that we have finished with the Sleeping Security Guard interaction part of the game, next we will work on the Game Manager.