Adding Cinemachine to Our Loot Chest Sequence

If you don’t have Cinemachine imported into your project, that is the first thing you will need to do.

We’ll click on the Cinemachine tab at the top of our Unity Editor and Click Virtual Camera.

Go ahead and rename the VCam as appropriate, reset the Transform component of the VCam game object, and then drag it as a child of the Treasure Chest game object.

Now, we can create a Cinemachine track on our ChestOpen Timeline and then drag our VCam onto the Timeline.

Most of the time your CinemachineBrain component will be on your Main Camera game object.

That may not be the case always, so I just want to point out that the Camera with the CinemachineBrain component is the one you want for our next step.

We drag our Main Camera with Cinemachine Brain component onto our Cinemachine Track in the ChestOpen Timeline.

I’ve also added the PlayerFollowCamera that comes with Unity’s 3rd Person Starter Asset into my scene and set its priority to 12, so it will take precedence over the loot chest VCam with a priority of 10.

Now, by default a follow player camera will activate when the game starts instead of the static main camera I had previously or the new loot VCam.

Next, we need to reposition and rotate our VCam to have a nice angle on the Treasure chest.

I’ve set the VCam for the loot chest to activate about 1/3rd of a second into the sequence.

On our ChestOpen Timeline, we can see where the Crown in the chest (1st) disables and the Crown on the character head (2nd) enables.

I want to line up the end of my loot chest VCam just a moment after this completes.
Once a player has a new hat, they want to walk and turn around to get a good look at it!

My loot VCam settings are pretty straight-forward.

I have the priority at 10, less than the player follow camera.

I’ve set the look-at on the crown in the loot chest and the aim settings are default Composer.

When the chest opens, the VCam should track the rising crown reward.

And yes, when we test it out, everything appears to be working as designed!

Forcing the Player to Sit Still

If we want to disable the player’s ability to move during our sequence, we can do that by adding a couple signal emitters to a new signal track.

Create the signals as shown above.

Next, add a Signal Receiver component to the character game object with the player controller on it.

Now, we want to control our Third Person Script component on the Player game object.

On the Signal Receiver component, add 2 reactions as shown above.

When the Signal CharFreezeOn is called we want to disable the ThirdPersonController script.

Likewise, with CharFreezeOff, we want to do the opposite.

On our player character game object, Signal Receiver component, we need to add 2 reactions for the animator component being enabled or disabled as well.

Now, I’ve already got my player game object animation track on the scene, but to add it just drag the player game object onto the Timeline’s left panel, select Animation Track.

Then drag an idle animation onto the Timeline.

I choose to move my freeze character signal emitter about 1 second into the timeline so that this character animation to idle could have time to blend.

So then, holding control key on and left-clicking the left side of the idle animation clip, drag it to the right to create a triangle similar to that above.

Left click and drag the right side of the idle clip and line it up with the FreezeOn signal emitter.

Now, it is CRITICAL to right click your animation track of the player character game object and set the Track Offsets to “Apply Scene Offsets”.

This will allow the animation to pick up on where the character game object currently is and smoothly blend in the idle animation without the character game object sliding across the screen.

Just to review what the end Timeline for ChestOpen looks like, I’ve included the above gif.

You should have a similar result to that shown above!



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