Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Zoom out to follow object using Tracked Dolly (with Auto)

Discussion in 'Cinemachine' started by myazuid, Jan 26, 2022.

  1. myazuid

    myazuid

    Joined:
    Jan 29, 2019
    Posts:
    26
    Hello,

    I am using the Auto Dolly to have the camera follow a specific path for a 2D platform type game. This has solved one of the problems I had with a regular framed transposer in that the camera didn't always show what the player needed to see. However, I have a different problem now which is that when the player moves their character off the line of the Smooth Path, they go off camera.

    I have written a script to change the orthographic size when this happens, but it doesn't work all that reliably, quickly becomes quite complex to do.

    I know there are ways of doing this with perspective cameras, but I can't see any built in way to do it with the current setup. Can anyone provide any tips on how I should tackle this problem?

    To restate it to be sure I've been clear:

    "I have a camera that follows a Smooth Path which is designed to follow a platform (2D). The player can sometimes move away to a lower platform that isn't on this path and they go off camera. I would like the camera to zoom out (orth. size?) when this happens so that they player always remains in view of the camera."

    Many thanks in advance.
     
  2. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    Hello myazuid,

    Check the CinemachineTargetGroup component. It's resizing your the camera to fit 2 transforms in the view. One transform should be your player and the other would be your dolly cart. Let us know if this works for you.
     

    Attached Files:

  3. myazuid

    myazuid

    Joined:
    Jan 29, 2019
    Posts:
    26
    Ah, interesting ok, I couldn't quite think how to use that...

    I don't think I have a dolly cart as I have Auto Dolly enabled? Or am I missing something? is the virtual camera the dolly?

    Have attached inspector of my vcam.

    edit - Just doing some reading about dollies, so yeah it looks like I don't have one at the moment as it is using auto-dolly to follow the target. So I guess I need to make a dolly component that moves down the Smooth Path to be as near the player as possible, so I can do what you suggest?
     

    Attached Files:

    Last edited: Jan 26, 2022
  4. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    156
    In your case I think it would be better to use a dolly cart instead of Auto Dolly. It will allow you to have a separate transform (The dolly cart) that you could track with the target group. You may have to do to a little bit of coding on the dolly cart to have the same behaviour but the setup will be much cleaner.

    Here is a basic setup to make it follow the player.
    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class DollyFollowPlayer : MonoBehaviour
    5. {
    6.     public Transform player;
    7.  
    8.     public CinemachineSmoothPath path;
    9.  
    10.     public CinemachineDollyCart cart;
    11.  
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.         cart.m_Position = path.FindClosestPoint(player.position, 0, -1, 10);
    16.     }
    17. }
    Check also this thread
     

    Attached Files:

  5. myazuid

    myazuid

    Joined:
    Jan 29, 2019
    Posts:
    26
    Brilliant. Thank you so much for your help, really appreciate it.