Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

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:
    3
    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:
    1,831
    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.
     
    ShervinM likes this.
  3. ShervinM

    ShervinM

    Joined:
    Sep 16, 2017
    Posts:
    3
    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!!