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);
}
}



