Ready for Battle Cutscene Using Timeline and Cinemachine

Dennisse Pagán Dávila
Geek Culture
Published in
6 min readMar 21, 2023

--

When combining Cinemachine and Timeline, another example we can look at is a cutscene that is activated when the character walks into a trigger. This is usually the kind of “event” cutscene that interrupts your gameplay as you walk into a certain area of your map like when you enter a new area and you’re given a view of your surroundings — a point of interest in an area, or when the player’s attention is needed to acknowledge threat before a battle.

Table of Contents

· Ready for Battle Stance Animation
· Adding a Virtual Camera
· Adding a Threat or Point of interest
· Coding the Scene Trigger
· The Result

If you’re new to Cinemachine and Timeline, make sure to check out my previous articles.

Ready for Battle Stance Animation

This is the stance the player takes as the cutscene triggers. A game will often set the player to an idle stance when a cutscene starts if the cutscene won’t focus on them.

When they are in the cutscene, they are instead animated, and gameplay is completely locked while the animation plays. Since we are using an independent animation, meaning one that is not linked to any of the animations appended to gameplay, our ability to move the character is locked for the duration of the animation.

  1. Add a cube that is large enough for you to undoubtedly collide when you get to the point where you want your cutscene to start. Don’t worry, we’ll be toggling off the mesh renderer so this cube is invisible to the player.

2. Make sure to toggle on “Is trigger” so the player can walk right through it and so that we can detect collisions via code.

3. Add your Director and Timeline to an empty game object.

4. Add the player as an Animation Track.

Here I want to add a sort of battle stance animation that the player assumes in preparation for a threat. By adding this animation, the gameplay is interrupted until it plays out.

Press record → Drag and drop your animation. You can get free animations at Mixamo. Be sure to check out this quick guide if it’s your first time working with imported animations.

5. Make sure the animation starts at the adequate position, sometimes adding an animation will change your character’s position. To correct this, select your clip in Timeline and use Clip Transform Offsets from the Inspector.

You should position your character where you want the animation to take place, which is right at the trigger zone.

Adding a Virtual Camera

For a cutscene, we also need to take control of the camera if not the player can retain access to their regular camera and move it around. We’ll be using Cinemachine for this.

2. Create a virtual camera via Cinemachine → Virtual Camera. You may choose any type of camera in Cinemachine, and position them however you like. I went with a regular virtual camera which I then positioned to be close to the right side of the archway.

3. Drag and drop your virtual camera to your Timeline and select Add with Cinemachine Track when prompted to. You can drag your

4. Make sure to drag your Cinemachine brain into the respective slot on your Timeline. This is your Main Camera with the red Cinemachine icon next to it.

Tip: You can add some ease in/out for any of your clips to smooth between transitions. I’ve added ease in and our for the idle/battle stance animation and the camera.

Adding a Threat or Point of interest

If your cutscene is to be triggered at a point of interest you can simply just have your virtual camera focus on it, then when the cutscene is triggered, the camera change will happen thanks to our Cinemachine Track. However, if you have a threat like an enemy, you might want to animate that well.

Note: You can learn more about Timeline animations here.

  1. Add a new Animation Track for the Enemy. I’ve affectionately named this robot Bailey😇 , an asset I got from Filebase.

2. Press the record button and start adding keys for your animation. As always, I started by adding a key at the default position.

3. Once you’re done adding keys, right-click and convert to clip.

The animation I created for little Bailey here is a simple moving forward motion and added a bit of head movement to with rotation. The idea behind this is that the “threat” moves into view as the camera focuses on it. You will see this in play soon.

Coding the Scene Trigger

We only need a few lines of code to get this going, nothing too complicated.

1. First, we need a specific namespace to access our Playable Director, which is what will play our Timeline sequence.

2. Now we need to declare a global variable with a SerializeField so that it’s assignable in the Inspector. This variable will be of type Game Object because we’ll use our Empty Game Object(the one holding the Timeline and Director), to grab its Playable Director.

3. Let’s detect OnTrigger collisions. We use tags to make sure this is only applicable when the Player collides with this trigger.

_Director.Play is accessed through the global variable we created before.

4. Our final step is to assign the script to our trigger object(the cube), and then assign the Cutscene_Director(Empty Game Object), to our newly created slot in the Inspector.

The Result

The cutscene plays when we walk into our trigger.

Once the cutscene ends, gameplay resumes.

I hope you have found this information valuable! Follow me for more Unity Development articles! :) I am a passionate Unity Developer and Writer on a journey to join the video game industry. Check out my LinkedIn and Twitter!

--

--

Dennisse Pagán Dávila
Geek Culture

Software Engineer that specialize in Game Development. Currently looking for new opportunities. LinkedIn: https://rb.gy/xdu8nu