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.

Resolved Isometric Virtual Follow Camera with two locked axis

Discussion in 'Cinemachine' started by ManuelRauber, Mar 26, 2022.

  1. ManuelRauber


    Apr 3, 2015
    Hi there!

    I currently struggle to setup a isometric virtual follow camera with two locked axis.

    Take a look at the following picture, this is what the player will see:


    The red lines are the world boundary. The red dot will be the player later.

    CameraRig setup

    PlayerFollow vCam

    As you can see, I've used the root object to rotate the camera, whereas the vCam is just a child of the rotated root object.

    The red lines you'll see in the first picture, are simply global Z-Forward. They are not rotated or something.
    By that, the player itself will also only move on Z-Forward and X-Axis.

    What I currently want to achieve is:

    • Camera follows the player on Z.
    • Camera does not follow the player on X or Y.

    The thing is, that when the player moves forward, due to the rotation of the CameraRig, the vCam X/Y/Z will change while following, so I can not set a fixed value.

    I'm also thinking if that is the correct setup for an isometric camera? I've read that somewhere on forum that the setup should be like this. However, what also seems to work is to not rotate the CameraRig but the vCam instead. If I would setup the scene like that, I can simply lock X/Y on the camera because now only Z will change. But I'm not sure if setting it up like this would have some other consequences that I don't know yet.

  2. Gregoryl


    Unity Technologies

    Dec 22, 2016
    First, you should take the main camera out of the Camera rig. It should be a game object by itself. The CM Brain will ensure that it exactly tracks the vcam.

    Next, you should try using FramingTransposer in the vcam instead of Transposer. You can set a very large dead zone so that the camera ignores X/Y movement of the target.

    If that doesn't work, then can you post a small video showing the incorrect movement? It's a little difficult for me to understand just from your description.
  3. ManuelRauber


    Apr 3, 2015
    That is just for organization. I do not move one of the parents at runtime. That part is working as expected. :)

    Now, I ended up with rotating the vCam instead of the parent and added a little script for locking X/Y-values of the vCam:

    Code (CSharp):
    1. [SaveDuringPlay]
    2. [AddComponentMenu("")]
    3. public class CinemachineLockToXYOffset : CinemachineExtension
    4. {
    5.   private float _xOffset;
    6.   private float _yOffset;
    8.   protected override void Awake()
    9.   {
    10.     base.Awake();
    12.     if (!VirtualCamera || VirtualCamera is not CinemachineVirtualCamera virtualCamera)
    13.     {
    14.       return;
    15.     }
    17.     var transposer = virtualCamera.GetCinemachineComponent<CinemachineTransposer>();
    19.     if (!transposer)
    20.     {
    21.       return;
    22.     }
    24.     var offset = transposer.m_FollowOffset;
    26.     _xOffset = offset.x;
    27.     _yOffset = offset.y;
    28.   }
    30.   protected override void PostPipelineStageCallback(CinemachineVirtualCameraBase vcam, CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    31.   {
    32.     if (stage == CinemachineCore.Stage.Body)
    33.     {
    34.       var position = state.RawPosition;
    36.       position.x = _xOffset;
    37.       position.y = _yOffset;
    39.       state.RawPosition = position;
    40.     }
    41.   }
    42. }
    It works as expected now :)