Search Unity

How to use Cinemachine Camera Offset

Discussion in 'Cinemachine' started by pau1o-hs, Jul 13, 2019.

  1. pau1o-hs

    pau1o-hs

    Joined:
    May 16, 2017
    Posts:
    5
    Hi! I'm trying to do a third person shooter camera, with character more to the left, using the Cinemachine Free Look and Camera Offset extension. But apparently the offset extension isn't being considered in the Collider extension, so it's like the camera offset is always (0, 0, 0). How to solve that?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    It's a little tricky getting this to work well with a FreeLook. CameraOffset and Collider don't play well together.

    People have had some success using an ordinary vcam with FramingTransposer + POV. It works well with collider, and you don't need the CameraOffset. Here is an example scene with that setup. Give it a try and tell me what you think.
     

    Attached Files:

    Levi-Burton likes this.
  3. praesidenter

    praesidenter

    Joined:
    Mar 5, 2016
    Posts:
    36
    Hi, I'm having the same problem with the collider not properly working when using the free look camera in combination with the offset extension. I tried the unitypackage from the previous answer and it's very jittery and doesn't feel as good to play as the free look camera even after finetuning the settings. You also lose the advantages and features of the free look cam and its different orbits, which is a shame because the free look camera and offset extension actually work very well together - that is until you consider collision.
    The POV workaround is not really a proper solution, I think, so I wanted to ask if there might be another way to have the free look camera and the collider work with offsetting the camera slightly to the side? To my understanding that is exactly what the offset extension is there for?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    The POV solution should not be jittery. If it is, then you might be tripping over some other issue, or maybe you didn't integrate it properly with your project.

    One thing you might want to try in order to get the camera offset to work better with the collider: set the script execution order to be such that Offset happens before Collider. If you're using the latest version, the offset extension will adjust the LookAt point, so then collider will use the adjusted LookAt as a reference rather than the original LookAt.
     
    Last edited: Aug 17, 2019
  5. praesidenter

    praesidenter

    Joined:
    Mar 5, 2016
    Posts:
    36
    Unfortunately that doesn't work. I changed the script execution order like you suggested (by changing the meta files like mentioned here, but the results are the same - the camera clips through walls when I activate the offset. I'm using the latest version available for me from the package manager (2.3.5 - preview.3) in Unity 2019.1.6f1.
     
  6. EMdevv

    EMdevv

    Joined:
    Mar 11, 2020
    Posts:
    6
    Any update on this issue? I really want to take advantage of the feature rich free-look camera and have an offset to create an over the shoulder perspective, but the collision just doesn't work with the offset component.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    The bottom line on this one is that FreeLook just isn't the optimal camera rig for an over-the shoulder TPS game. FreeLook is designed for following and looking at a player, not for following the player while looking over its shoulder at something else.

    Have a look at some of the new sample scenes shipped with CM 2.6: AimingRig and 3rdPersonWithAimMode. Both of those show an over-the-shoulder setup that works much better than FreeLook. AimingRig has built-in collider logic.
     
  8. EMdevv

    EMdevv

    Joined:
    Mar 11, 2020
    Posts:
    6
    Thanks for the response. I checked out the sample scenes you mentioned and while the collision works in them, you still miss out some essential features by not using a free-look camera, in particular the top-middle-low rig setup for smooth orbiting of the character. Having free-look camera with a offset component works fine for a TPP perspective, it's just that the collider doesn't want to take the offset into consideration.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    If it's just the orbit-distance-as-a-function-of-vertical-angle that you're missing, it's quite easy to tack that on. I think it's worth the effort, because the results are much better. Are there other FreeLook features that you would miss?
     
  10. EMdevv

    EMdevv

    Joined:
    Mar 11, 2020
    Posts:
    6
    Not that I can think of. The easily adjustable orbits is the main feature I'm missing from the other cameras.
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    If you attach this script to the AimingRig sample vcam, it will give you the orbit control that you're looking for.

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class AimingRigDistanceController : MonoBehaviour
    5. {
    6.     public float BaseDistance = 2;
    7.     public float MinAngle = -90;
    8.     public float MaxAngle = 90;
    9.     public AnimationCurve DistanceScale;
    10.     Cinemachine3rdPersonFollow TpsFollow;
    11.     Transform FollowTarget;
    12.  
    13.     void Start()
    14.     {
    15.         var vcam = GetComponentInChildren<CinemachineVirtualCamera>();
    16.         if (vcam != null)
    17.         {
    18.             TpsFollow = vcam.GetCinemachineComponent<Cinemachine3rdPersonFollow>();
    19.             FollowTarget = vcam.Follow;
    20.         }
    21.     }
    22.  
    23.     void Update()
    24.     {
    25.         if (TpsFollow != null && FollowTarget != null)
    26.         {
    27.             var xRot = FollowTarget.rotation.eulerAngles.x;
    28.             if (xRot > 180)
    29.                 xRot -= 360;
    30.             var t = (xRot - MinAngle) / (MaxAngle - MinAngle);
    31.             TpsFollow.CameraDistance = BaseDistance * DistanceScale.Evaluate(t);
    32.         }
    33.     }
    34. }
    I used these settings:

    upload_2020-5-22_9-15-13.png

    with the curve like this:

    upload_2020-5-22_9-15-56.png

    You can use a similar approach to make a distance modifier for the 3rdPersonWithAimMode-style vcam.
     
    mmcveigh33 and EMdevv like this.