Search Unity

Cinemachine Y-Axis dampening on Stairs

Discussion in 'Cinemachine' started by JayArtist, Jan 7, 2022.

  1. JayArtist

    JayArtist

    Joined:
    Jul 1, 2014
    Posts:
    89
    Hi,

    I'm attemping a 3D platformer currently using Cinemachine's Freelook camera and Unity's built in Character Controller. All seems good, however I'm having issue with the character moving upwards.

    When the player goes up the steps, or a single small cube, the camera movement is juddery in the Y-Axis and too sudden. I can't seem to find a way to dampen the movement of the camera - walking down seems much smoother in comparison.

    Is there an option to smooth or dampen the Y-Axis movement with some kind of small delay?

    Perhaps it is more to do with Unity's Character Controller coupled with Cinemachine?

    Does anyone have any ideas?

    Cheers, Jay.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Can you show the inspector for your vcam?
     
  3. JayArtist

    JayArtist

    Joined:
    Jul 1, 2014
    Posts:
    89
    Hi, sure, here's the Cinemachine FreeLook Setup:



    I've set the Y Axis Control Speed to zero as I don't require this movement - with it on doesn't change the issue.

    Also here's my player controller script for reference:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerMovementAlt : MonoBehaviour
    6. {
    7.     public float speed;
    8.     public float rotationSpeed;
    9.     public float jumpSpeed;
    10.  
    11.     private Animator animator;
    12.     private CharacterController characterController;
    13.     private float ySpeed;
    14.     private float originalStepOffset;
    15.  
    16.     [SerializeField]
    17.     private Transform cameraTransform;
    18.  
    19.  
    20.     void Start()
    21.     {
    22.         animator = GetComponent<Animator>();
    23.         characterController = GetComponent<CharacterController>();
    24.         originalStepOffset = characterController.stepOffset;
    25.     }
    26.  
    27.  
    28.     void Update()
    29.     {
    30.         float horizontalInput = Input.GetAxis("Horizontal");
    31.         float verticalInput = Input.GetAxis("Vertical");
    32.  
    33.         Vector3 movementDirection = new Vector3(horizontalInput, 0, verticalInput);
    34.         float magnitude = movementDirection.magnitude * speed;
    35.  
    36.         // Player follow camera direction
    37.         movementDirection = Quaternion.AngleAxis(cameraTransform.rotation.eulerAngles.y, Vector3.up) * movementDirection;
    38.  
    39.         movementDirection.Normalize();
    40.  
    41.         ySpeed += Physics.gravity.y * Time.deltaTime;
    42.  
    43.         if (characterController.isGrounded)
    44.         {
    45.             characterController.stepOffset = originalStepOffset;
    46.             ySpeed = -0.5f; // reset gravity
    47.             if(Input.GetButtonDown("Jump"))
    48.             {
    49.                 ySpeed = jumpSpeed;
    50.             }
    51.         }
    52.         else
    53.         {
    54.            characterController.stepOffset = 0f;
    55.         }
    56.  
    57.      
    58.  
    59.         Vector3 velocity = movementDirection * magnitude;
    60.         velocity = AdjustVelocityToSlope(velocity);
    61.         velocity.y += ySpeed;
    62.  
    63.         characterController.Move(velocity * Time.deltaTime);
    64.      
    65.         if (movementDirection != Vector3.zero)
    66.         {
    67.             animator.SetBool("isMoving", true);
    68.             Quaternion toRotation = Quaternion.LookRotation(movementDirection, Vector3.up);
    69.             transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);
    70.         }
    71.         else
    72.         {
    73.             animator.SetBool("isMoving", false);
    74.         }
    75.     }
    76.  
    77.     // Fix Slope bobbing
    78.     private Vector3 AdjustVelocityToSlope(Vector3 velocity)
    79.     {
    80.         var ray = new Ray(transform.position, Vector3.down);
    81.  
    82.         if (Physics.Raycast(ray, out RaycastHit hitInfo, 0.2f))
    83.         {
    84.             var slopeRotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);
    85.             var adjustedVelocity = slopeRotation * velocity;
    86.  
    87.             if(adjustedVelocity.y <0)
    88.             {
    89.                 return adjustedVelocity;
    90.             }
    91.         }
    92.  
    93.         return velocity;
    94.     }
    95.  
    96.     // Hide Mouse Pointer
    97.     private void OnApplicationFocus(bool focus)
    98.     {
    99.         if(focus)
    100.         {
    101.             Cursor.lockState = CursorLockMode.Locked;
    102.         }
    103.         else
    104.         {
    105.             Cursor.lockState = CursorLockMode.None;
    106.         }
    107.     }
    108.  
    109. }
    110.  

    The script was taken from a series of tutorials on YouTube:
    https://www.youtube.com/channel/UC_t8wVOpvTIxQvmDiEgbniQ
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Do you have a CinemachineCollider on the vcam? If so, disable it and see whether that makes the judder go away.

    If you don't need the Y control, you can replace the FreeLook with a simple vcam with OrbitalTransposer in the Body. Much more lightweight and better-performing.

    Can you show a video of the judder? It might be your controller script moving the character unevenly, and the camera is just tracking it.
     
  5. JayArtist

    JayArtist

    Joined:
    Jul 1, 2014
    Posts:
    89
    I've just tested the standard Cm Vcam1 and this doesn't have any judder. However the OrbitalTransposer doesn't work right, it just goes nuts.

    I'm trying to create a 3D platformer, where the left stick controls the movement of the player ( forward, back, turn etc) and the right stick roates the camera - similar to Mario 64.

    I'll have to do a recording and upload - I'm working on that ;)
     
  6. JayArtist

    JayArtist

    Joined:
    Jul 1, 2014
    Posts:
    89
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Nuts? Can you provide some detail? A FreeLook is just 3 vcams with orbital transposers, so there's no reason why a single one will go nuts if you use the same settings.

    Do the 3 rigs in your FreeLook have damping in the Aim section? The judder looks rotation-related rather than position-related. Can you show that part of the inspector?
     
  8. JayArtist

    JayArtist

    Joined:
    Jul 1, 2014
    Posts:
    89
    "Nuts", Yeah a good technical term, sorry.

    I added a basic Virtual Camera with the Framing Transposer in the body, which works totaly fine, although obviously no control on the right analogue stick.

    When I add the Orbital Transposer in the body:

    Left Stick Forward, moves the player forward and the camera follows.
    Left Stick Backwards the player moves backwards and the vm cam follows until you turn the player, then it just shudders and shakes uncontrollably.
    Right Stick Rotates the camera left/right totally fine.

    I'm assuming the script I have is set up more for the Freelook Camera, but because I'm not familar with coding Cinemachine, I don't know exactly what's going on.

    Here's the Basic Virtual Camera with the Orbital Transposer:
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    The settings are not the same as the FreeLook. Change the Binding Mode to SimpleFollowWithWorldUp.
     
  10. JayArtist

    JayArtist

    Joined:
    Jul 1, 2014
    Posts:
    89
    Bit of a long day for me - my head is fried! thanks, I'll check that out tomorrow - I'll get back here then if there is any success or not. Thanks for your effort
     
  11. JayArtist

    JayArtist

    Joined:
    Jul 1, 2014
    Posts:
    89
    Hi Gregoryl,

    This method is working now, everything is now smooth. Again thanks for the help.

    I'm including a screenshot for anyone who's interested:



    Jay.