Course contentsShow
← Unity Game Development
Lesson 397 of 8286. Animation and CinemachineFree lesson

Implementing Multi-Target Framing with Cinemachine Target Groups

Learners will configure target groups to dynamically adjust camera framing based on the average position of multiple game objects.

In this lesson, you will learn how to use the Cinemachine Target Group component to keep multiple game objects within the camera’s frame simultaneously.

The Concept of a Target Group

When a camera needs to follow a single player, setting the Follow target is straightforward. However, when you need to capture a dynamic group—like a pair of players or a squad of NPCs—a static target isn't enough. The CinemachineTargetGroup acts as a "virtual anchor" that calculates the center point and the bounding box of multiple objects in real-time.

Configuring the Group

To set this up, create an empty GameObject in your scene and attach the CinemachineTargetGroup component. Under the Targets list, you can add any number of Transforms.

Each target has two important properties:

  • Weight: How much influence this object has on the center point. A weight of 2 means the camera will lean closer to this target than an object with a weight of 1.
  • Radius: How much "space" the object occupies. The camera uses this to ensure the framing isn't too tight, preventing objects at the edge of the screen from being clipped.

Linking to the Virtual Camera

Once your group is populated, go to your CinemachineVirtualCamera. Instead of dragging a specific player into the Follow slot, drag your TargetGroup GameObject there. The virtual camera will now automatically track the center of the group and adjust its zoom (if Body is set to Framing Transposer) to ensure every target in the list remains visible.

For example, if you are creating a local multiplayer arena, adding the players to a TargetGroup ensures that as they move apart, the camera pulls back, and as they move together, it zooms in:

// You can even add targets at runtime via script
public CinemachineTargetGroup group;
public Transform newPlayer;

void AddPlayerToCamera(Transform playerTransform) {
    group.AddMember(playerTransform, 1f, 2f); // Add with weight 1 and radius 2
}

This dynamic approach keeps your cinematography fluid without needing complex custom camera controllers.

Key Takeaway: By assigning a CinemachineTargetGroup as the Follow target for a Virtual Camera, you offload the complex math of averaging positions and calculating bounding boxes to Cinemachine, ensuring all subjects stay perfectly framed.