Today I made something pretty complicated, to grab the attention of the player when it’s needed. The music changes and the camera moves from the player position to an important object the player needs to investigate. The camera stays there for a few seconds, and then moves back to the player again. After that, the normal background music returns.
To make sure the object stays in focus, depth of field needs to be turned off temporarily (the aperture needs to be set to max) when the camera is near the object. For this Unity’s badly documented post-processing volume needs to be addressed. Also, player control must be cancelled when the camera is traveling, else the player will be able to move the traveling camera, so that it will never arrive at its original position anymore. Not only that, the player would be able to move the camera away from the object in question too, so that he would never notice it. These issues have all been addressed.
What made this most difficult was the fact that the behaviour of some of the objects involved in Unity (Post Processing Stack, Audio Mixer) differs from their behaviour outside Unity, making it very hard to debug the code. Another very annoying bug was the fact that the player could slide from the landscape during the cutscene, so that he would trigger the end of said cutscene halfway by leaving the cutscene zone involuntarily. I solved this by expanding the zone while playing the cutscene (not very elegant, but it does the job).
I think this is a very cool feature that we’ll use pretty often in the game.