How can I implement a functional third person movement and freelook camera on unity 20221.3.3f1

Hello everyone! How’s it going?

It’s been awhile since I’m having this issue, my 3rd person character movement based on a rigid body addforce(), takes the camera forward vector as one of the directional parameters, since I need a general 3rd person character where if the character turn the camera lef 90º and press the correspondent key to forward, it would actually go forward according to the camera forward instead of the character forward global orientation. Most 3rd person game has it. Turns out my CineMachine camera is jittering when I turn it around the character, I’m assuming it’s because of the movement or some configuration on cinemachine.

And I realized that if I just dont use the camera forward to also dictates the global directions for the player movement it just dont jitter, so I first thougt it could be the way that my camera is set to update, like should it be Smart Update? Late Update? etc, none of my tries worked.

I’ve been struggling to fix that but then I moved on to another strategy, which is getting a 3rd person sample that actually uses cinemachine FreeLook and just use it, adjusting to specific needs. But turns out that every 3rd person template is a big deal to make it work on this unity version (2021.3.3f1), either to make the inputs conversion to old or the newsest unity imputs or code that is too deprecated and takes so much effort to fix.

Is there any template or sample I could use for this verion that attends to this needs? My camera gotta be something like Life is Strange camera, just a free movement around the character and dictates the forward direction related to the camera. Or maybe is there a missing config I could do on Cinemachine side to make it not jitter when I rotate around the character / rotates the character?

Thank you very much!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;

public class CharacterMovement : MonoBehaviour
{
    public float speed = 10.0f;
    public CinemachineFreeLook cmFreeLook;
    public Rigidbody rb;
    public float rotateSpeed = 10.0f; // added this to control the rotation

    public Transform virtualPos;
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");

        virtualPos.position = Camera.main.transform.position;
        virtualPos.LookAt(this.transform.position);

        Vector3 cameraForward = virtualPos.transform.forward;//camTran.transform.forward;

        //Vector3 cameraForward = cmFreeLook.transform.forward;
        cameraForward.y = 0f; //To prevent character from jumping
        cameraForward = cameraForward.normalized;

        Vector3 movement = cameraForward * vertical + Camera.main.transform.right * horizontal;

        rb.AddForce(movement * speed);

        Quaternion targetRotation = Quaternion.LookRotation(movement);
        transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rotateSpeed * Time.deltaTime);
    }
}

8747631--1184931--cm_brain.PNG



I think the problem is in your controller script, not in Cinemachine. If you are controlling a RigidBody, you must add force in FixedUpdate, not in Update. Also: do you have interpolation enabled on the RigidBody?

Have a look at the PlayerMovePhysics.cs script that ships with the CM samples. I think it does what you need.

I’ve tried it on the fixed update for the movement and on the update for the inputs previously too, and it stills, I’ve actually tried many scripts and stills. The interpolation were off, I’ve turned it on and minimzed it a bit, but didn’t solve it. I’ve also realized that the Brain configuration for the Update method also influenses how strong the jittlering gets.

After a few tests with only the CineMachine in a blank project, with only the CM and the defaults inputs and CM Free Look Character Sample, I’ve noticed there stills a few jittering also, and, I noticed that it happens when you rotate the character around itself, in other words, when the “Mouse X” input influences the character movement, it will jitter with small bumps when rotating the camera, if you dont have influence of the “Mouse X” it doesn’t happens. I’ve also noticed that is more noticeable when you have already started the game in a scaled down screen (editor), probably because the mouse input is related to the screen viewport size, when the game is full screen or played maximized it happens in a much more smaller and acceptable scale of a jittering.

Would like to know if I’m missing aconfiguration on it that could solve it.

CM Brain Update Method = Smart Update
FreeLook = default FreeLook camera
CM = 2.8.4 (also tried the latest on the blank project 2.9.5)

Does it happen when you make a build of the scene? Unity editor has lots of overhead that can introduce framerate irregularities.