Search Unity

FramingTransposer at fixed height

Discussion in 'Cinemachine' started by c0ffeeartc, Jun 17, 2019.

  1. c0ffeeartc

    c0ffeeartc

    Joined:
    Jul 23, 2015
    Posts:
    42
    Hello, I'd like to have framing transposer that keeps its height fixed for top down camera ( rotation 75, 0, 0 ). Can this be achieved easily, or how would I add/modify transposer?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    You could try making a custom extension that forces the camera Y to a fixed value, maybe like this:
    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. /// <summary>
    5. /// An add-on module for Cinemachine Virtual Camera that locks the camera's Y co-ordinate
    6. /// </summary>
    7. [SaveDuringPlay] [AddComponentMenu("")] // Hide in menu
    8. public class LockCameraY : CinemachineExtension
    9. {
    10.     [Tooltip("Lock the camera's Y position to this value")]
    11.     public float m_YPosition = 10;
    12.  
    13.     protected override void PostPipelineStageCallback(
    14.         CinemachineVirtualCameraBase vcam,
    15.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    16.     {
    17.         if (stage == CinemachineCore.Stage.Body)
    18.         {
    19.             var pos = state.RawPosition;
    20.             pos.y = m_YPosition;
    21.             state.RawPosition = pos;
    22.         }
    23.     }
    24. }
    25.  
    Drop it into your project, it will appear automatically in the vcam's Extensions dropdown.
     
    TJHeuvel-net and c0ffeeartc like this.
  3. c0ffeeartc

    c0ffeeartc

    Joined:
    Jul 23, 2015
    Posts:
    42
    Wow, thanks. Will try it
     
    Gregoryl likes this.