Search Unity

Cinemachine 2D Camera Deadzone Height Limitation

Discussion in 'Cinemachine' started by segasega89, Oct 13, 2019.

  1. segasega89

    segasega89

    Joined:
    Feb 10, 2019
    Posts:
    48
    Hi there,

    I'm just trying at the moment to construct a camera system similar to the one that's seen in Super Mario World on the SNES using Cinemachine.

    Basically I have a Cinemachine 2D camera that follows the player(represented by a red rectangle) but I don't want the virtual camera to follow the player when it jumps very high. I want the vertical axis of the virtual camera to be stable at all times.
    I have the deadzone height of the camera set at its maximum value but it still doesn't seem to be high enough to prevent the camera from following the player vertically once the player reaches a certain height.

    I've attached a video of my project here:


    Any help would be appreciated.

    Kind regards,
     
    tsef likes this.
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Hmmm... you seem to have indeed tripped over a limitation. The soft zone can stretch to 2, but the dead zone can only stretch to 1. There is no good reason for that, so we will fix it for the next CM release. Thanks for letting us know!

    In the meantime, there are a couple of ways to implement a workaround:
    1. You can set the screen Y to 0.5, and then the dead zone height of 1 will be enough to fill the screen. You will just need to start your camera off on the ground - then the dead zone will take care of keeping the camera from moving vertically.
    2. You can add a custom extension to manage the vcam's Y position. Here is one that locks it to a specific value. You can modify it to handle the camera Y any way you like.
      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.  
     
  3. tsef

    tsef

    Joined:
    Jul 8, 2018
    Posts:
    2
    faced the same problem, the solutions proposed to you do not help to solve situations, since the center of camera watching the character is moves, but must remain static.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    If you want the camera to remain 100% static, then don't follow the player.
    If you want the Y position of the camera to remain static, but track the player's X position, then you can attach the script from the post above.