Search Unity

Question How to choose the camera type ?

Discussion in 'Cinemachine' started by Pytchoun, Mar 18, 2023.

  1. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    Hello,

    I do a top down shooter. Camera is like for example Diablo or last stand aftermath.
    But how to choose the camera type ? I don't see a camera type named "Top down". We have a lot of choice and all choice can do the same thing ?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    For this you want a camera that remains at a fixed angle, at some fixed world-space offset from the target. Is that correct?

    So: make a CinemachineVirtualCamera, with these settings:
    • Follow target: your player
    • LookAt target: your player
    • Body: Transposer with
      • BindingMode = WorldSpace
      • FollowOffset = (desired camera position relative to the player)
    • Damping = (whatever you like)
    • Aim: DoNothing
    Set the vcam's rotation to be what you like. With Aim set to DoNothing, it will remain there.

    Here is a shortcut to center the player on-screen:
    • Set Aim to HardLookAt,
    • Adjust the follow offset in Transposer to that the camera is positioned where you want it (it will self-adjust its rotation to keep the player centered on the screen)
    • Set the Aim back to DoNothing
    • If you now want to fine-tune the rotation to adjust character position on screen, you can do that now
    It's best to put DoNothing in Aim, because if you add damping to the transposer (which is a good idea to make the camera less mechanical), then the rotation will remain constant. With HardLookAt, the rotation would continuously adjust.
     
  3. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    Hi,

    Thanks for your reply.

    Yes. Something like that.

    At this time i copy the TPS Unity sample Camera and have this settings.
    upload_2023-3-18_16-15-41.png

    I will try your to find if it is better.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Yes, a top-down style camera is not well implemented by 3rdPersonFollow behaviour. The way I described is better.
     
  5. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    Ok i will try, i use this script also for customize my camera behaviour:
    https://pastebin.com/kr2NzmEn
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    That script will not work without the 3rdPersonFollow. Can you describe exactly the camera behaviour you want? What I described above will make the camera have a fixed angle and offset from the player. What do you want the user to be able to change?
     
  7. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    I have a custom script for the user can rotate the camera around the player character and be able to zoom also.
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Some questions:
    1. Are you using the Input package or the legacy input system?
    2. When you say "zoom" do you mean that you want the camera distance to change, or that you want the FOV to change?
    3. Do you want damping on the camera or do you want it to be rigidly attached to the player?
     
  9. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    1. I use the new input system.
    2. I want the camera distance to change.
    3. I don't want damping.
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    In that case, you can do something like this. It will handle the orbiting for you, but for the zoom you will have to make a custom script that scales vcam.GetCinemachineComponent<CinemachineOrbitalTransposer>().m_FollowOffset in response to the user's zoom commands.

    upload_2023-3-18_11-51-11.png
     
  11. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    Thanks for your sample, i will try on my side.
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Here is a script to control the zoom. Attach it to the vcam. It uses the InputProvider's Z Axis to control the zoom.

    upload_2023-3-18_12-12-16.png

    Code (CSharp):
    1. using UnityEngine;
    2. namespace Cinemachine
    3. {
    4.     [RequireComponent(typeof(CinemachineVirtualCamera))]
    5.     class OrbitalTransposerZoom : MonoBehaviour
    6.     {
    7.         private CinemachineOrbitalTransposer m_Orbital;
    8.         private Vector3 m_OriginalOffset;
    9.  
    10.         [Tooltip("The minimum scale for the orbit")]
    11.         [Range(0.01f, 1f)]
    12.         public float MinScale = 0.5f;
    13.         [Tooltip("The maximum scale for the orbit")]
    14.         [Range(1F, 5f)]
    15.         public float MaxScale = 1;
    16.         [Tooltip("The zoom axis.  Value is 0..1.  How much to scale the orbit")]
    17.         [AxisStateProperty]
    18.         public AxisState ZoomAxis = new AxisState(0, 1, false, true, 1f, 0.1f, 0.1f, "Mouse ScrollWheel", false);
    19.         void OnValidate()
    20.         {
    21.             MinScale = Mathf.Max(0.01f, MinScale);
    22.             MaxScale = Mathf.Max(MinScale, MaxScale);
    23.         }
    24.         void Awake()
    25.         {
    26.             var vcam = GetComponent<CinemachineVirtualCamera>();
    27.             m_Orbital = vcam.GetCinemachineComponent<CinemachineOrbitalTransposer>();
    28.             if (m_Orbital != null)
    29.             {
    30.                 m_OriginalOffset = m_Orbital.m_FollowOffset;
    31. #if UNITY_EDITOR
    32.                 SaveDuringPlay.SaveDuringPlay.OnHotSave -= RestoreOriginalOrbit;
    33.                 SaveDuringPlay.SaveDuringPlay.OnHotSave += RestoreOriginalOrbit;
    34. #endif
    35.             }
    36.  
    37.             // Locate the input axis provider to drive the zoom axis
    38.             ZoomAxis.SetInputAxisProvider(2, vcam.GetInputAxisProvider());
    39.         }
    40. #if UNITY_EDITOR
    41.         private void OnDestroy()
    42.         {
    43.             SaveDuringPlay.SaveDuringPlay.OnHotSave -= RestoreOriginalOrbit;
    44.         }
    45.         private void RestoreOriginalOrbit()
    46.         {
    47.             if (m_Orbital != null)
    48.                 m_Orbital.m_FollowOffset = m_OriginalOffset;
    49.         }
    50. #endif
    51.         void Update()
    52.         {
    53.             if (m_Orbital != null)
    54.             {
    55.                 ZoomAxis.Update(Time.deltaTime);
    56.                 float scale = Mathf.Lerp(MinScale, MaxScale, ZoomAxis.Value);
    57.                 m_Orbital.m_FollowOffset = m_OriginalOffset * scale;
    58.             }
    59.         }
    60.     }
    61. }
    62.  
     
    Last edited: Mar 18, 2023
    mcaldei01 likes this.
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    The player control based on the ThirdPerson starter asset might not work so well with this setup, I haven't tested it. For reference, here is my test scene, with all the scripts.
     

    Attached Files:

    mcaldei01 likes this.
  14. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    Thanks, i will look at this.