Search Unity

How do I lock rotation when using the group composer?

Discussion in 'Cinemachine' started by ShervinM, Sep 30, 2018.

  1. ShervinM

    ShervinM

    Joined:
    Sep 16, 2017
    Posts:
    67
    Hi there, firstlyI want to describe my set up:
    • Orthographic camera
    • Empty target group object that is rotated 45 degrees about X (I want my camera to always be at 45 degrees X), and rotation mode set to manual
    • CM Vcam with a Framing Transposer and Group Composer component.

    Now the vcam seems to frame my objects, but the issue is that it'll do all sorts of rotations as the objects move. I dont want any of these rotations, and wish to keep my camera always at a fixed height, and 45 degree rotation about the X axis. I have a Vcam extension to lock the height (so thats not a problem), but I cant seem to solve the rotation.

    I tried to make the following extension to lock the rotation (very similar to the height lock script), but this didnt work either:
    ==================================================================

    using UnityEngine;
    using Cinemachine;

    /// <summary>
    /// An add-on module for Cinemachine Virtual Camera that locks the camera's rotation
    /// </summary>
    [ExecuteInEditMode]
    [SaveDuringPlay]
    [AddComponentMenu("")] // Hide in menu
    public class LockRotation : CinemachineExtension
    {
    [Tooltip("Lock the camera's rotation to this value")]
    public Quaternion m_lockedRotation = Quaternion.Euler(new Vector3(45, 0, 0));

    protected override void PostPipelineStageCallback(
    CinemachineVirtualCameraBase vcam,
    CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    {
    if (enabled && stage == CinemachineCore.Stage.Body)
    {
    state.RawOrientation = m_lockedRotation;
    }
    }
    }

    ==========================================================================

    The best I've been able to achieve, is by changing the body to a Transposer (and not a Framing Transposer), and setting the binding mode to "Lock To Target On Assign". But this still does a very minor rotation when my objects move (eventually zeroing out).

    EDIT: Also, I should mention that I want to keep dead zone widths. Is this possible with the group composer? It seems (regardless of wonky rotations, and before any scaling of ortho size), the camera moves with every frame when my objects move even though I have strict dead zones set.

    Finally, another observation I've made is that in "Aim", with Group Composer selected, how come I dont see the "Adjustment Mode" option? Not sure if this in any way related, but figured I'd mention it (see attached picture of my Vcam component).

    Any help would be greatly appreciate it. Sorry for the wall of text :(
     

    Attached Files:

    Last edited: Sep 30, 2018
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    You almost had it :)
    Body controls the vcam position, and Aim controls the vcam rotation. If you don't want the vcam to rotate, you have to put DoNothing in Aim.
    So: FramingTransposer in Body, and DoNothing in Aim. That will leave the vcam's rotation as you set it, while tracking and framing your group.
     
  3. ShervinM

    ShervinM

    Joined:
    Sep 16, 2017
    Posts:
    67
    A brilliant! Thank you Gregory! I just noticed that if I place a group as the FollowTarget it provides me with more options within Body (FramingTransposer) relevant to tracking/framing the group.

    Many thanks!!
     
  4. B4ttleCat

    B4ttleCat

    Joined:
    Mar 31, 2014
    Posts:
    18
    Very sorry to necro this, but is there a way to get the min and max ortho sizes and lock the rotation? When you choose "do nothing" you lose these options and these are necessary to the effect I'm going for.
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    If you have Framing Transposer in the Body, and Do Nothing in the Aim, and your Follow Target is a group, then you get these options in the Framing Transposer.
     
    Whatever560 and B4ttleCat like this.
  6. B4ttleCat

    B4ttleCat

    Joined:
    Mar 31, 2014
    Posts:
    18
    Thank you so much @Gregoryl. That worked perfectly.
     
  7. MuratBingol

    MuratBingol

    Joined:
    May 20, 2021
    Posts:
    3
    Alternatively you can try this:
    create an empty object.
    Constantly synchronize the position information of this empty object with the position information of the ball in the update method.
    Follow this empty object with the camera.
    In this way, you will only follow the position of the ball.
     
  8. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    518
    The exact thing I was missing, should it be considered to add a note on the Target Group Documentation? I see the note on the FramingTransposer now but it seems a better entry point for people looking to handle groups.
    https://docs.unity3d.com/Packages/c....8/manual/CinemachineTargetGroup.html?q=group

    (Not using the 3.0 yet but looks like the "Framing" is already noted) equivalent) https://docs.unity3d.com/Packages/c...al/CinemachineTargetGroup.html?q=target group