Search Unity

Framing Transposer coordinate space

Discussion in 'Cinemachine' started by Nerglej, Jul 24, 2021.

  1. Nerglej

    Nerglej

    Joined:
    Mar 19, 2018
    Posts:
    5
    Hello!
    I have a Virtual FreeLook Camera as my main camera, in a third person scene. In the Freelook camera there's a Binding Mode property where I can select Lock To Target With World Up based on the up from the Cinemachine Brain on the Camera. The 'With World Up' is important because the scene changes gravity so the cameras World Up and movement changes accordingly.
    Orbits.jpg

    But I also need an Aiming Camera. I've created another Virtual Camera (not a FreeLook Cam), where I have a Framing Transposer for the Body and POV for the Aim, so I can, well, aim the camera with the mouse.
    The only problem i have is that the Framing Transposer is locked to the standard World Up and doesen't change acordingly to the Cinemachine Brains World Up which makes weird results when the gravity changes.

    Skærmbillede 2021-07-24 151214.jpg '

    I could use the FreeLook third person cam again to the aim, but I need the Sceen X and Y to correctly place the camera.

    How would I go about making the Framing Transposer be affected by World Up?
    Or should I make a Cinemachine Extension to try and mimic the function of Screen X and Y on Framing Transposer (and how would I do that)?

    I would prefer the first question, but if that isn't possible would you help come up with another solution with an extension? Thanks in advance :D
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    The FramingTransposer/POV combo unfortunately does not automatically handle the WorldUp override in the Brain. A simple workaround is to make a custom extension that sets the world up directly. Here is one:
    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. /// <summary>
    5. /// An add-on module for Cinemachine Virtual Camera that overrides Up
    6. /// </summary>
    7. [SaveDuringPlay] [AddComponentMenu("")] // Hide in menu
    8. public class CustomCameraUp : CinemachineExtension
    9. {
    10.     [Tooltip("Use this object's local Up direction")]
    11.     public Transform m_Up = null;
    12.  
    13.     public override void PrePipelineMutateCameraStateCallback(
    14.         CinemachineVirtualCameraBase vcam, ref CameraState curState, float deltaTime)
    15.     {
    16.         curState.ReferenceUp = m_Up.up;
    17.     }
    18.  
    19.     protected override void PostPipelineStageCallback(
    20.         CinemachineVirtualCameraBase vcam,
    21.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    22.     {
    23.     }
    24. }
    25.  
    If you add it to your vcam and set m_Up to be your player, it should work properly.

    ...HOWEVER...

    It seems that there is a bug in CinemachinePOV that prevents this from working. We will fix this for the next CM release, but in the meantime here is a patched version. Just drop it into your project and use it instead of CinemachinePOV.

    Thank you for the question, because it led to the discovery of this bug :)
     

    Attached Files:

    Nerglej likes this.
  3. Nerglej

    Nerglej

    Joined:
    Mar 19, 2018
    Posts:
    5

    Well, thanks! I'm happy that I helped you find a bug :)
    It's working as it should now, and I'm looking forwards to the patch!
     
    Gregoryl likes this.
  4. Nerglej

    Nerglej

    Joined:
    Mar 19, 2018
    Posts:
    5
    I am really sorry to awaken this thread again since I stated that the scripts you provided were working.
    Since I restarted Unity it's not working again, and I've really been trying anything with the settigns in Cinemachine to get it working proberbly.

    I didn't change anything when I started Unity, I'm using the Custom POV you provided, and I'm using the extension.
    While it wasn't working I updated Cinemachine from 2.6.5 to 2.8.0, but it's still not working...
    Do you have any ideas?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    You'll have to elaborate on what you mean by "not working".
    Can you put together a sample project that shows the problem?
     
  6. Nerglej

    Nerglej

    Joined:
    Mar 19, 2018
    Posts:
    5
    So I didn't really know how to upload a Unity project so I posted a sample project to GitHub: https://github.com/Nerglej/GravityCameraCinemachine
    This only contains the necessary files and the bug is still here. When you press play in the SampleScene, you can see that the Main VCam works properbly and the Aim VCam also works, when you rightclick. But then try walking up the wall, I've added gravity there. The Main VCam still works proberbly, until you rightclick to get the Aim VCam, which is still oriented with the default world up.
    The Aim VCam is using the scripts that you provided, unchanged since my changes didn't work.
    I don't know if it's something with the Input System, since I'm not using the built in system, but I don't think thats it since it's only input and not camera orientation.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Thanks for the upload. The problem is because the POV vcam is parented. The POV behaviour always moves relative to its parent object's axes, if there is a parent. Only if there is no parent does it consider the world axes, and that's the case where the CustomCameraUp will make a difference. Running your test scene, if I move the Player Aim Camera out of the hierarchy, it starts to work correctly.

    So, you have 3 options:
    1. Ensure that the Player Aim vcam has no parent object when running,
    2. Have the transform of the Player Aim vcam match the custom world up,
    3. Change CinemachineCustomPOV to override the parent object (just comment out the "else" at line 136).
     
  8. Nerglej

    Nerglej

    Joined:
    Mar 19, 2018
    Posts:
    5
    Thank you! I choose option number 3, since the Aim VCam is part of a prefab :D
     
    Gregoryl likes this.