Search Unity

Resolved Unity3D Loop-De-Loop Movement Camera Jitter Issues

Discussion in 'Cinemachine' started by Queen_Kazma, Apr 13, 2023.

  1. Queen_Kazma

    Queen_Kazma

    Joined:
    Feb 5, 2022
    Posts:
    15
    Hello, everyone. I've had running in loop de loops working for a while now but every time the player changes the surface they are on inside the loop, the rest of the world seems to stutter as the player runs through. I've been trying to find a solution to this for quite a while now and am stumped. I've included a 30 second clip of the issue in action:


    Additionally, the only place that I reference the camera in the PlayerMovement.cs code is when I'm redefining and normalizing the player input based on the current movementPlane (because we're upside down in the loop):

    Vector3 playerInput = new Vector3(horizontalInput, 0, verticalInput);
    playerInput = cameraTransform.TransformVector(playerInput);
    playerInput = Vector3.ProjectOnPlane(playerInput, movementPlane);
    playerInput.Normalize();

    I'm quite sure this is a Cinemachine issue and would appreciate any insight into a possible fix.
     
  2. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    189
    Heyyoo :)
    Are you using the world up override? Is there steps in the rotation of your target?

    If yes I am not aware of a feature built in that would fix that. There is no Damping applied to it. but you could easily damp this value.

    Create a new GameObject called SlerpWorldUp and replace it in the world override field of the Brain.

    Attach this script

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class SlerpTransform : MonoBehaviour
    5. {
    6.     public Transform target; // Your player
    7.     public float speed = 1; // The speed of the slerp
    8.    
    9.     //Change this to the update method of your cm brain
    10.     private void LateUpdate()
    11.     {
    12.         transform.position = target.transform.position;
    13.         transform.rotation = Quaternion.Slerp(transform.rotation, target.transform.rotation, Time.deltaTime * speed);
    14.     }
    15. }
    Assign the target field.

    Screen Shot 2023-04-13 at 1.20.18 AM.png

    Hope this helps let us know.
     
  3. Queen_Kazma

    Queen_Kazma

    Joined:
    Feb 5, 2022
    Posts:
    15
    @antoinecharton - Thank you very much for showing me this! Based on what I observed after implementing it, this resolved the stuttering issue. I was using the 'Player (transform)' as the value for the 'World Up Override' field and there are a few steps involved in rotating the player to the new surface in the PlayerMovement.cs code. That said, there were 2 changes that I did need to make to your recommendations, though:
    1. The first was just to change the name of the 'SlerpWorldUp' GameObject to 'CameraDelegate'. Just a personal preference/convention, on my end.
    2. The second was an issue with the code itself; namely renaming the LateUpdate() to what is selected in the 'Update Method' dropdown. I currently have 'SmartUpdate' selected but renaming the 'LateUpdate()' function to 'SmartUpdate()' completely breaks the ability to run in the loop so I just left it as 'LateUpdate()'. I hope that was what you meant, unless there is a different 'SmartUpdate()' function that I need to be using? Although, I was pretty sure that SmartUpdate simply picked between the different Update functions for the best one, unless I'm mistaken.
     
    Last edited: Apr 13, 2023
    antoinecharton likes this.