CinemachineFreeLook Jitters/Deforms during Movement.

Cinemachinefreelook Jitter/Deforms during Rotation

Hi, I’ve been having a ton of trouble getting cinemachinefreelook to work with my movement and rotation. I am trying to make a simple platformer and my rotation speed seems to be messed up in turn with my camera rotation. I am using the new unity input system and posting a visual of it, before the square deforms it was jittering and I don’t know the right combo of settings to get this to work smoothly.

Simply put I want the camera to be rotatable and the player to rotate on their own too with it all being smooth.

My movement code is inside FixedUpdate():

private void Move()
        {
            Vector3 moveDirection = new Vector3(moveInput.x, 0f, moveInput.y).normalized;
            Vector3 cameraForward = Camera.main.transform.forward;
            cameraForward.y = 0;
            cameraForward.Normalize();
            Vector3 cameraRight = Camera.main.transform.right;
            cameraRight.y = 0;
            cameraRight.Normalize();
  
            Vector3 desiredDirection = cameraForward * moveDirection.z + cameraRight * moveDirection.x;
            rb.velocity = new Vector3(desiredDirection.x * moveSpeed, rb.velocity.y, desiredDirection.z * moveSpeed);
  
            if (desiredDirection != Vector3.zero)
            {
                Quaternion targetRotation = Quaternion.LookRotation(desiredDirection, Vector3.up);
                rb.MoveRotation(Quaternion.RotateTowards(rb.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime));
            }
        }

could anyone help with this who may have used this component before?

[Jitter]

[CinemachineFreeLook]

[Player Gameobject]

[MainCamera]

I have tried many types of settings and no setup works.

It could be your binding mode. You’ve got it locked to the target so that means the camera will rotate with the target. Try using World Space binding mode instead.

I’ve actually tried a bunch of binding modes and started with simple follow world up. The only thing that seemed to work was turning AIM to none but then the camera would not look at the player.

It actually got better when I turned my player rotate speed variable to match similar to the camera rotate speed so I assumed maybe its something to do with the camera lagging behind or an issue with the unity cinemachine input.

I’ve tried a lot of options and nothing really works so I can tell you all of the ones I have attempted, from changing the brain updates, to the binding mode, to the dampening, rigidbody interp… and so on. But it seems like such a simple thing?

If I understand correctly, you want to decouple player rotation and camera rotation, One set of controls to rotate the payer, another set to rotate the camera. You want user input to be relative to camera, so move forward will make the player walk in the direction that the camera is pointing. Is that right?

If so, then WorldSpace and SimpleFollow are the only options for BindingMode. All the others will couple the rotations. There is no reason that the rotations should get mixed up. Can you show your scene hierarchy? Maybe you have a parenting issue.

Have a look at the Free Look character sample scene that ships with CM. It’s doing what you’re looking for, I think

Yes so Ill better explain my expected logic. Moving forward will walk the player where the camera is going, turning left/right will turn the player/player model in that direction. Using the mouse or other control stick will rotate the camera around the player.

I have tried worldspace/simplefollow as well. I cannot show the scenespace right now but I can provide a link to my repository for this project: GitHub - Ceruin/Mischief-Makers-Legends: 3D Mischief Makers

I did try looking at the Third Person Unity default and copying some of those features but it seems they do not use the cinemachine input for rotating the camera nor do they use rigidbodys.

“Have a look at the Free Look character sample scene that ships with CM. It’s doing what you’re looking for, I think”
I can try that as well but its so odd the jitter always occurs.

Let’s put jitter issues aside for now, because there are many possible causes for jitter. First we have to get the basic movement right. To do that, you have to stop changing random things, and start with a basic setup that is correct. Please refer to the Free look character sample and set your camera up the same way.

Ok, I won’t be able to work on this again until later tonight. Could you point to me where I would find the Cinemachinefreelook sample, should I already have it?

Thanks for the help so far, I will get back to you on if it works or not later tonight.

So I opened it up after importing and literally copy pasted a few things.
I still run into this problem which is wild.

My Active setup:

8965980--1232202--upload_2023-4-21_20-0-52.png

    private void FixedUpdate()
    {
        Move();
    }

   private void Move()
    {
        Vector3 moveDirection = new Vector3(moveInput.x, 0f, moveInput.y).normalized;
        Vector3 cameraForward = Camera.main.transform.forward;
        cameraForward.y = 0;
        cameraForward.Normalize();
        Vector3 cameraRight = Camera.main.transform.right;
        cameraRight.y = 0;
        cameraRight.Normalize();

        Vector3 desiredDirection = cameraForward * moveDirection.z + cameraRight * moveDirection.x;
        rb.velocity = new Vector3(desiredDirection.x * moveSpeed, rb.velocity.y, desiredDirection.z * moveSpeed);

        if (desiredDirection != Vector3.zero && desiredDirection.magnitude > 0.1f)
        {
            //Quaternion targetRotation = Quaternion.LookRotation(desiredDirection.normalized, Vector3.up);
            //rb.MoveRotation(Quaternion.RotateTowards(rb.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime));
            //rb.MoveRotation(Quaternion.LookRotation(desiredDirection));

            Quaternion targetRotation = Quaternion.LookRotation(desiredDirection.normalized, Vector3.up);
            var diferenceRotation = targetRotation.eulerAngles.y - transform.eulerAngles.y;
            var eulerY = transform.eulerAngles.y;

            if (diferenceRotation < 0 || diferenceRotation > 0) eulerY = targetRotation.eulerAngles.y;
            var euler = new Vector3(0, eulerY, 0);

            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(euler), turnSpeed * rotationSpeed * Time.deltaTime);
        }
    }

8965980--1232211--upload_2023-4-21_20-3-26.png
Example:
8965980--1232214--upload_2023-4-21_20-4-4.gif

I am still having this issue. Should I just redo my project?

Heyyoo :slight_smile:
You are moving your cube in fixed update. If you change the update method to fixed update on your Cinemachine brain does you still see the jitter?

Yes I still see the jitter, it’s more of a stutter now but yeah.

here is the visual:
8967495--1232607--upload_2023-4-22_21-51-53.gif

problem still occuring.

In the Time settings of the Project Settings, there’s a Fixed TimeStep value:

This defaults to 0.02 (1/50), and has done forever. And is far and away one of the most retarding things in all of Unity’s defaults. It’ll trip you up in all sorts of ways if left at this value and you’re working with physics.

Initially, set this to double your desired frame rate: ie if you’re aiming for 60fps, set this value to 1/120 = 0.00833333

And now see if all the woes of your physics vs your fixedStep updating of Cinemachine have resolved.

If they have, try backing off the setting to the same as the frame rate: 1/60 = 0.0166666 or thereabouts.

There are all sorts of other little problems with time and ticks in the Unity engine. But hopefully none of them should appear for something as basic as this. By way of example, if you sample how many times fixedUpdate is called versus the amount of time passed, it’s inconsistently inconsistent, even in the newer “fixed” versions of Unity.

This actually did seem to help a lot! there are some issues still and some questions. Then how do you make a physics based game in Unity with variable framerate. Does this setting have to be adjusted based on a max framerate setting?

I also get it very slightly stuttering still but it does seem to greatly change things. Do you know why the stutter might have improved but still be there? Do I need to lock the framerate?

try setting the CM Brain back to LateUpdate.

If that doesn’t fully fix things now physics timestep is more sensible, I’ll have to have a ponder.

1 Like

So I tried this and changed some of my code back from the cinemachine sample the others had me try. I now use LateUpdate on the brain. Interpolote for the Rigidbody, World space for my cinemachine with aim on composer and my FixedUpdate movement/rotation code:

    private void Move()
    {
        Vector3 moveDirection = new Vector3(moveInput.x, 0f, moveInput.y).normalized;
        Vector3 cameraForward = Camera.main.transform.forward;
        cameraForward.y = 0;
        cameraForward.Normalize();
        Vector3 cameraRight = Camera.main.transform.right;
        cameraRight.y = 0;
        cameraRight.Normalize();

        Vector3 desiredDirection = cameraForward * moveDirection.z + cameraRight * moveDirection.x;
        rb.velocity = new Vector3(desiredDirection.x * moveSpeed, rb.velocity.y, desiredDirection.z * moveSpeed);

        if (desiredDirection != Vector3.zero && desiredDirection.magnitude > 0.1f)
        {
            Quaternion targetRotation = Quaternion.LookRotation(desiredDirection.normalized, Vector3.up);
            rb.MoveRotation(Quaternion.RotateTowards(rb.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime));
        }
    }

Overall this seems to work a lot better. I don’t really see jitter, I do see FPS drops but maybe that’s only in editor sometimes(?).

Here is a visual sample to make sure i’m not crazy lol. It looks like the char still trys to turn some but not really jitter nor stutter?:
8968996--1232914--upload_2023-4-23_23-55-2.gif

Ok so the in-game when built is fairly bad. It stutters hard
8968999--1232920--upload_2023-4-23_23-57-57.gif