Daily progress, June 11, 2021: Sleeping Guard
Todays work is to integrate the sleeping security guard cutscene into the stealth mini-game.
There’s a box collider around the sleeping guards desk called a LevelCollider/Grab_Cut_Scene_Zone where it will trigger when Darren walks into it. Like the other trigger scripts before it, it’s a simple case of creating a holder for the cutscene, and then checking to see if _Player collided with the box-collider. To be sure, we’ll need a rigidbody if there isn’t one.
First let’s create the script we’ll be attaching to the Grab_Cut_Scene_Zone:
Next, we’ll drag our actual cutscene into the holder via the inspector.
Ok, let’s check if it works…
Whoa! That’s no good! Gameplay Darren is still there while CutScene Darren is playing! Gameplay Guard is there too, Let’s make them disappear for a bit.
In the Cutscenes timeline, create 3 new activation tracks, one for Darren, the other for the guard, and one for the cutscene itself. We need for a way for the cutscene to deactivate once its over and what better way with itself?
For the cutscene itself, It’s 360 frames, so we’ll have it activated until 359 frames and deactivate at the last frame. For the sleeping guard and the player, just push both till the end and shorten it to a couple frames at the end so they’ll activate after we fade to black (which we’ll do later).
Next we added a fade to black at the end so we can make our game assets appear again safely.
For some reason, the activation track wasn’t working in gameplay mode. Darren would disappear while I scrubbed the timeline, but as soon as I played the game, he’d appear as his clone worked away at stealing the guards card. As I’m working on Unity in Linux, I feel I have to be forgiving of the engine since it’s formally a Windows program. I think I may reluctantly reinstall windows 10 soon. Anyway, I finally just took things into my own hands and manually turned Darren and the Guard off by creating handles for both and temporarily deactivating them in a coroutine.
The next issue that came up was after the cut-scene stops playing, the camera doesn’t return to its former position. The solution is to create a new virtual camera with the same position and rotation of the current cutaway camera, and place it one frame before the scene ends.
There was one more issue where there was an error moving with the NavMesh, and that was because the cutscene camera was still being used instead of the main one. The solution was to add another activation track for the main Cutscene and deactivate it one frame before the end, but because I manually disabled the cutscene in the Grab_Cut_Scene_Zone level collider, the problem didn’t come up in the first place!
Tomorrow, we’ll talk about creating Manager classes!