Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved RPG camera mouse drag (CineMachine)

Discussion in 'Scripting' started by JhonnyRage, Dec 2, 2020.

  1. JhonnyRage

    JhonnyRage

    Joined:
    Feb 23, 2017
    Posts:
    54
    Hi everyone i got a little script that controls the camera w the mouse drag... the script is working "Fine" right now
    Code (CSharp):
    1.  
    2.  
    3.         public static CameraController Instance { get; set; }
    4.         public Camera GameplayCamera;
    5.         private Transform Camerajig;
    6.         public CinemachineVirtualCamera CVC;
    7.         public float Speed = 6f;
    8.    
    9.         public CinemachineVirtualCamera Camera { get; protected set; }
    10.  
    11. //-------------------------------------------------------------------------------------------------------------------------
    12.  
    13.         void Update()
    14.         {
    15.             if (Input.GetMouseButton(1))
    16.             {
    17.                 if ( Input.GetAxis("Mouse X") > 0 || Input.GetAxis("Mouse X") < 0)
    18.                 {
    19.                     transform.RotateAround(Camerajig.position, Vector3.up, Input.GetAxisRaw("Mouse X") * Speed * Time.deltaTime);
    20.                 }
    21.  
    22.                 if (Input.GetAxis("Mouse Y") > 0 || Input.GetAxis("Mouse Y") < 0)
    23.                 {
    24.                     transform.RotateAround(Camerajig.position, Vector3.right, Input.GetAxisRaw("Mouse Y") * Speed * Time.deltaTime);
    25.                 }
    26.  
    27.             }
    the "issue" is that when i drag the mouse to move the camera it glitches a bit on up/down also it feels a bit rough... i would like to get some feedback on how to improve this code, thanks in advance.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Get rid of Time.deltaTime from your calculation. Mouse Axis values are already framerate independent, so the inclusion of deltaTime actually introduces jitter.
     
    JhonnyRage likes this.
  3. JhonnyRage

    JhonnyRage

    Joined:
    Feb 23, 2017
    Posts:
    54
    oooh i see... yeah that should be obvious hahaha, thanks.
     
  4. JhonnyRage

    JhonnyRage

    Joined:
    Feb 23, 2017
    Posts:
    54
    update: the script above works really nice if u need it just take it and remember remove the delta time.