Cinemachine and Group Targets in Unity
Objective: To learn how to keep multiple targets in the frame.
Cinemachine is absolutely fantastic with being able to keep a single target in the frame, but is it able to do this with multiple targets? Let’s take a look at a ‘Group Composer’ feature in the ‘Aim’ settings.
What is the Group Target ‘Aim’ Setting in Cinemachine?
This setting is Cinemachines way of saying let’s take a bunch of individual targets and treat them as if it was 1 ‘LookAt’ target.
Let’s Get This Virtual Camera Setup
To start let’s add the virtual camera to the scene, ‘Cinemachine’ tab → ‘Create Virtual Camera’. This will now be added as a game object in your scene.
Next we are going to create the ‘TargetGroup’ game object and add a CinemachineTargetGroup component to it. Create Empty Game Object in Hierarchy → Rename to ‘TargetGroup’ → Add component in the Inspector ‘CinemachineTargetGroup’:
Now let’s change the ‘Aim’ setting in the CinemachineVirtualCamera component in the Inspector and also add the newly created ‘TargetGroup’ to the ‘LookAt’ field:
You might be met this small error, which is perfectly fine. It is basically letting us know that there is no group targets added to the component yet. So let’s add some!
But first, we need to add a couple cubes to either side of the capsule so that we have multiple targets:
Now, let’s add these targets to the CinemachineGroupTarget component on the ‘TargetGroup’ game object:
On your Game view tab, you may now see these yellow lines across the screen which is going to help us track multiple targets to be in the same frame:
Let’s Test It!
It is time to see if our magic has paid off. We are hoping to see that when we move the capsule back and forth, the virtual camera will automatically adjust itself to make sure that all the targets are in the same frame:
Success!! That was super easy to setup and we haven’t even begun to play around with all the additional settings available to us in the ‘Aim’ settings and also the ‘CinemachineTargetGroup’ component: