So, I am making a video game using the 3rd person Cinemachine camera and a character as its focus. So far so good, but one problem I have come across is the player seems to be twitching back and forth unnaturally while it turns. I have set the y rotation of the player to update on every FixedUpdate to equal the rotation of the Camera. I suspect this is the cause of the issue, (As I am directly updating the y-rotation every FixedUpdate with rigidbody.MoveRotation) however, I don’t know Cinemachine well enough to know how to fix this, or know another easy way to make the camera and player smoothly turn together. Any help would be appreciated. Thanks!
Sorry for the slow response, there have been issues with my notifications.
It’s hard to pinpoint the problem without more details, but if you’re using the camera position as input for your character rotation, one problem that can crop up is reading the camera position before Cinemachine has updated it for the frame, and therefore using a stale position from the previous frame.
CinemachineBrain updates the camera position in LateUpdate, and it has a late execution order. An easy solution is for your character controller to hook into CinemachineCore.CameraUpdatedEvent, which is invoked immediately after the camera has been positioned. At that point, it’s safe to read the camera’s transform.
Thanks so much for responding, I wasn’t expecting anyone to respond after a month!
How would I hook into the event? I’m new to events so I may be doing something wrong, but so far I am trying to use CinemachineCore.CameraUpdatedEvent.AddListener(CameraUpdate); in Start() to listen for the event, but it keeps giving me an error of
error CS1503: Argument 1: cannot convert from 'void' to 'UnityEngine.Events.UnityAction<Cinemachine.CinemachineBrain>'
I feel like I am doing something wrong here, as according to what I looked at in the documentation, I should be able to put my function “CameraUpdate” into this function, but the error is saying it is the wrong type, and that it can’t convert.
Thank you!
Note: Yes, I am using Cinemachine
Your CameraUpdate function needs to take a CinemachineBrain parameter.
YES THAT WORKED!!!
Thank you so much, i’ve been working on this problem forever and couldn’t find a solution!