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

Question Cinemachine POV Look At issue

Discussion in 'Cinemachine' started by Auguin, Apr 28, 2021.

  1. Auguin


    May 23, 2018

    I use a virtual camera on a Tracked Dolly and POV aim.
    I want to recenter the view automatically on an object (a cube), but for now the view always recenter on start orientation.
    I configured my virtual camera like the bottom screen.


    Can someone as a solution to recenter on the cube and not the start orientation?

    Thanks for your help.
  2. gaborkb


    Unity Technologies

    Nov 7, 2019
    Under POV, the recenter target option's Look At Target Forward mode is going to recenter the view, so that the camera forward is parallel and in the same direction as the Look At Target Forward.

    If you'd like to recenter so that the camera is looking at the box, then you could write a script that will orient the box in a way that it's forward is the same as the camera-box vector.

    For example, like in the image here:
    Screen Shot 2021-04-29 at 7.38.07 AM.png

    See the example script that will accomplish this below. To use this attach the script to your box, and add the vcam to the script. If you don't want to visually rotate the box, you could have an invisible child gameObject and rotate and look at that instead.
    Code (CSharp):
    1. using Cinemachine;
    2. using UnityEngine;
    3. public class RotateMeSoCameraLooksAtMe : MonoBehaviour
    4. {
    5.     public CinemachineVirtualCamera vcam;
    6.     void Update()
    7.     {
    8.         var vcamMeVector = transform.position - vcam.transform.position;
    9.         transform.rotation = Quaternion.LookRotation(vcamBoxVector);
    10.     }
    11. }
    Last edited: May 11, 2021
  3. Auguin


    May 23, 2018
    Thanks for the solution !

    For others with the same issue, I just modify the script exemple to take the camera position instead of the virtual camera.
    gaborkb likes this.