Search Unity

How can I disable the free look camera zoom ?

Discussion in 'Cinemachine' started by SharonL75, Sep 18, 2020.

  1. SharonL75

    SharonL75

    Joined:
    Aug 13, 2020
    Posts:
    91
    In my settings on the Axis Control > Y Axis > Speed is set to 0.

    The reason I set the speed to 0 is that I don't like the zoom in/out when you rotate the camera with the mouse up/down.

    The X Axis speed is set to 300 and this is fine but the camera rotate only to the sides not up and down.
    I want to be able to rotate the camera also up and down but to clamp it so the camera will not get into the ground and not too much high above the head and without the automatic zomming.

    Any solution/s to avoid this zooming that make the camera getting close to the player when rotating/moving the camera up and down ?

    My Free Look Camera Settings :

     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    The way to control how high / low the FreeLook moves is to adjust the orbit heights:

    upload_2020-9-18_10-25-39.png

    That defines the range of the Y axis movement.

    I'm afraid I don't understand what you mean by "zoom". The FreeLook does not zoom the camera, it just moves it around on the surface defined by the 3 orbits you set. Can you describe in more detail the issue you're having?
     
    SharonL75 likes this.
  3. SharonL75

    SharonL75

    Joined:
    Aug 13, 2020
    Posts:
    91

    Here is a screenshot when I set the Y Axis Speed to value 2 and the middle rig in the orbit to Height 0.88 and Radius to 6.04 when I try to move the camera down to look down dragging the mouse down it's getting close to the player too much close :

    upload_2020-9-18_17-41-41.png

    When I'm dragging moving the mouse up :

    upload_2020-9-18_17-42-51.png

    What I want is to be able to move the camera with the mouse around looking 360 degrees to the forward view with clamp so it will not get too much to the ground and not too much above the player.

    But now if I move drag the mouse down the camera is getting very close to the player.
    I want a simple orbit camera or something close to it moving with the keys the camera will also set the moving direction but that you can look around also up and down.

    I can make also a small video clip to show how it is now.


    If the Y Axis Speed value is 0 then you can move the camera to the sides looking around and it's working fine but then you can't look up and down around only to the left and to the right. but if you set the Y Axis speed to 2 then you can move the camera looking up and down but it also getting too close to the player.
     
  4. SharonL75

    SharonL75

    Joined:
    Aug 13, 2020
    Posts:
    91
    It's not zoom maybe I described it wrong. but it makes the camera move too close to the player. I just want to be able to look around with the camera on all directions when moving the mouse around.
     
  5. SharonL75

    SharonL75

    Joined:
    Aug 13, 2020
    Posts:
    91

    Changing the Orbit heights or radius is not helping for my problem. When the Y Axis speed is set to 2 or more when trying to look around with the mouse it's making the camera moving very close to the player.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Maybe you should step back a little and describe exactly the kind of camera movement you want. I'm wondering whether what you want is to have the camera always positioned behind the player, but when you move the mouse it rotates the camera to look around, rather than changing its position. Is that what you want?
     
    SharonL75 likes this.
  7. SharonL75

    SharonL75

    Joined:
    Aug 13, 2020
    Posts:
    91
    Here is a short video clip showing the player movement and the camera behaviour.
    I can move the player with the keys and the camera will follow and also I can move the mouse and rotate the camera to look around. The problem is that I can;t move the camera up and down only looking to the sides around.

    I want to keep this camera behaviour idea but to add also the possible to look up and down a bit.

    The movement of the player and camera is starting from second 27 :

     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Video is private, can't view it.
     
    Last edited: Sep 18, 2020
    SharonL75 likes this.
  9. SharonL75

    SharonL75

    Joined:
    Aug 13, 2020
    Posts:
    91
    Fixed it, now it's public.

     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    ok. And what you want to do now is add the functionality that when you move the mouse up and down, the camera tilts up and down, without changing position? As if someone is holding the camera, and standing at the same spot just looks up and down? Is that right?
     
    SharonL75 likes this.
  11. SharonL75

    SharonL75

    Joined:
    Aug 13, 2020
    Posts:
    91
    Right, Even if the player just standing still or if I move the player around to be able to move the camera up and down without changing position. You right this is what I want to do.
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    ok thanks, I understand now.

    In this case, you don't need a FreeLook, as it's designed to move in a sphere-like orbit around the player. What you want is a disk-like orbit, plus the ability to tilt up and down.

    So replace the FreeLook with a simple Virtual camera with settings that mimic the Middle Rig of your FreeLook:
    • OrbitalTransposer in Body with WorldSpace Binding Mode, X Axis settings same as your FreeLook
    • Composer in Aim, same as your FreeLook middle rig
    That will give you the disk-like orbit.

    Next, for the look-up-and-down, you'll need a custom extension. Try this one. Drop it in your project, and it will be available in the vcam inspector's Extensions dropdown.
    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. /// <summary>
    5. /// An add-on module to tilt the Cinemachine Virtual Camera
    6. /// </summary>
    7. [SaveDuringPlay] [AddComponentMenu("")] // Hide in menu
    8. public class TiltCamera : CinemachineExtension
    9. {
    10.     [Tooltip("Control for how to tilt the camera")]
    11.     [AxisStateProperty]
    12.     public AxisState yAxis;
    13.  
    14.     /// <summary>Controls how automatic recentering of the Vertical axis is accomplished</summary>
    15.     [Tooltip("Controls how automatic recentering of the Vertical axis is accomplished")]
    16.     public AxisState.Recentering Recentering = new AxisState.Recentering(false, 1, 2);
    17.  
    18.     protected override void OnEnable()
    19.     {
    20.         base.OnEnable();
    21.         var provider = VirtualCamera.GetInputAxisProvider();
    22.         if (provider != null)
    23.             yAxis.SetInputAxisProvider(1, provider);
    24.     }
    25.  
    26.     private void OnValidate()
    27.     {
    28.         yAxis.Validate();
    29.     }
    30.  
    31.     private void Reset()
    32.     {
    33.         yAxis = new AxisState(-89, 89, false, false, 50f, 0.1f, 0.1f, "Mouse Y", false);
    34.     }
    35.  
    36.     protected override void PostPipelineStageCallback(
    37.         CinemachineVirtualCameraBase vcam,
    38.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    39.     {
    40.         if (stage == CinemachineCore.Stage.Aim)
    41.         {
    42.             // Update the axis value
    43.             if (deltaTime < 0 || yAxis.Update(deltaTime))
    44.                 Recentering.CancelRecentering();
    45.             if (deltaTime >= 0)
    46.                 Recentering.DoRecentering(ref yAxis, deltaTime, 0);
    47.  
    48.             // Apply the tilt
    49.             state.RawOrientation = state.RawOrientation * Quaternion.Euler(yAxis.Value, 0, 0);
    50.         }
    51.     }
    52. }
    53.  
    upload_2020-9-18_12-52-46.png

    upload_2020-9-18_12-53-1.png
     
    SharonL75 likes this.
  13. SharonL75

    SharonL75

    Joined:
    Aug 13, 2020
    Posts:
    91

    I just finished setting the virtual camera and not yet used the script.
    but I have a problem because before I had two free look cameras each in other position because when the game is starting I wanted to have a transition between the cameras so when there was two free look cameras it was moving backward from the first camera smooth changed to the second camera.

    but now with the virtual camera the transition is different.
    should I also replace the first camera from look to virtual and it will make the transition automatic ?
    the main goal is after a cut scene when the game start the camera move slowly smooth backward then switching to the second camera and then the player move and everything.
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    There is no reason to use a FreeLook for the first camera. Remember that the FreeLook is designed to move the camera on a sphere-like orbit in response to user input. That first camera is just sitting there. Change it to s simple virtual camera.
     
    SharonL75 likes this.
  15. SharonL75

    SharonL75

    Joined:
    Aug 13, 2020
    Posts:
    91
    The blending transition between the cameras is working but it's not moving backward straight line like when I used free look cameras. Now it's making kind of a circle moving around then to the other camera position.

    Why it's not moving straight backward ?

    I changed both cameras positions the first as before and duplicated and just moved the second a bit back using Follow Offset and on Aim on Tracked Object Offset X but the blending between the cameras is not straight line backward movement.

    The first virtual camera settings :



    The second virtual camera settings :



    Maybe it's not moving backward directly because I changed the second camera view by using the Follow Offset and on Aim on Tracked Object Offset X ? I tried just to drag the second camera by changing it's transform position but the camera is not moving.
     
    Last edited: Sep 18, 2020
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Try setting this option on the second camera:

    upload_2020-9-18_17-36-13.png

    You can't just drag virtual cameras around if they have procedural algorithms to position themselves in relation to a target. If you drag the vcam, it will adjust the offset relative to the target, not the vcam position directly.

    If your first vcam is a close-up of the head, then it should have a simple Transposer in Body, with the desired offset set. OrbitalTransposer is overkill, unless you expect to respond to user input.

    Body tell the camera where to position itself, Aim tells the camera what to look at once the camera is positioned. Aim in both cases should be the character, with no offset. It's the Body offset that matters (where the camera should stand in relation to the character).
     
    SharonL75 likes this.
  17. SharonL75

    SharonL75

    Joined:
    Aug 13, 2020
    Posts:
    91
    In the end I decided to stay with the free look cameras and added a script to the second free look camera the player camera and using the script to change with the mouse the middle rig > aim > tracked object offset on the y :

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using Cinemachine;
    6. public class CamerasControl : MonoBehaviour
    7. {
    8.     public CinemachineFreeLook freeLookCam;
    9.     public float clampMin;
    10.     public float clampMax;
    11.     public float pitch;
    12.     public float speed;
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.         pitch += speed * Input.GetAxis("Mouse Y");
    18.         pitch = Mathf.Clamp(pitch, clampMin, clampMax);
    19.         freeLookCam.GetRig(1).GetCinemachineComponent<CinemachineComposer>().m_TrackedObjectOffset.y = pitch;
    20.     }
    21. }
    22.  
    This is working just great for what I wanted.

    Starting from second 27 :