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

    ManuelRauber

    Joined:
    Apr 3, 2015
    Posts:
    81
    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:

    upload_2022-3-26_12-24-28.png

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

    CameraRig setup
    upload_2022-3-26_12-25-26.png
    upload_2022-3-26_12-25-35.png

    PlayerFollow vCam
    upload_2022-3-26_12-26-1.png

    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.

    Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,008
    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

    ManuelRauber

    Joined:
    Apr 3, 2015
    Posts:
    81
    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;
    7.  
    8.   protected override void Awake()
    9.   {
    10.     base.Awake();
    11.  
    12.     if (!VirtualCamera || VirtualCamera is not CinemachineVirtualCamera virtualCamera)
    13.     {
    14.       return;
    15.     }
    16.  
    17.     var transposer = virtualCamera.GetCinemachineComponent<CinemachineTransposer>();
    18.  
    19.     if (!transposer)
    20.     {
    21.       return;
    22.     }
    23.  
    24.     var offset = transposer.m_FollowOffset;
    25.  
    26.     _xOffset = offset.x;
    27.     _yOffset = offset.y;
    28.   }
    29.  
    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;
    35.  
    36.       position.x = _xOffset;
    37.       position.y = _yOffset;
    38.  
    39.       state.RawPosition = position;
    40.     }
    41.   }
    42. }
    It works as expected now :)
     
unityunity