Stuttering Camera

I’ve never used Cinemachine before, so it was nice to have a new tool in the box.

One of the things I have noticed with both my own implementation of a follow camera and the Cinemachine camera is that there seems to be some kind of camera stutter while the camera chases after the player (small but jarring), particularly as the environment gets larger. I’m not quite sure why this happens?

No idea what Cinemachine is.

It’s a package that was introduced in the 3D Introduction to Unity Course:

Basically, as far as my understanding goes (before really reading through the documents), it allows you to create a virtual camera (brain) within the scene to manage one or multiple existing cameras based on built in functions (i.e., whether you want to switch cameras the game scene is viewed through / have certain cameras remain stationary).

I think the issue is something more fundamental though, given stuttering occurs on my own camera implementation as well. Thinking about it afterwards I am wondering if it might have something to do with the fact that the player object I am following is moved with forces - and thus rotates - so the camera follow ends up getting influenced subtly by that?

Ah! You posted in the Blender section. Which in large part explains the lack of awareness. :rofl:

My bad. I thought I was putting the reply off the video, but I must have fiddled with something somewhere. I’m not sure if there’s a way to move this, but I’m not really to concerned if the question gets closed - I can probably figure something out over time.

1 Like

Moved it for you. Someone more likely to see it that knows something about it now.

1 Like

Hi,

Try to have the cinemachine brain be updated in Late Update. And you could also try to set the “Interpolate” value in the Rigidbody component of the player game object to “Interpolate”.

https://forum.unity.com/threads/stuttering-with-rigidbody-cinemachine.1141687/#post-7334470

Last but not least, if the issue persists, create a build and test it because the game window is just a (laggy) preview.

Did this help you fix the issue?


See also:

Thanks, I will have to try this on my desktop when I get back later this week. On my slower laptop I don’t see the same stuttering issues in the game window (though I am using a older version of unity in it). Hopefully it is just an issue with the game window itself and I can mark it as solved then.

(Trying it out on different hardware did introduce me to some new issues in my separate implementation of camera following outside of cinemachine where the smoothing / dampening of the following seemed to be much slower - perhaps not framerate independent - so I think this was a good experience in learning where testing on different machines might have value for those of us who can.)

Since you mentioned that you are using a laptop, make sure the power chord is plugged in. Otherwise, it might be that your operating system is running the power saving mode which makes everything much slower. Before you look for issues in your project, try to exclude that the problem is caused by your hardware.

It’s a good idea - in this case I am fairly confident that that’s not an issue here and that it has more to do with settings within my code. Fortunately there is a lot of documentation out there - might be getting a bit ahead of what might be being reviewed later in the courses, but I will put aside some time to review the functions I am using (as well as late update) before posting a solution and marking the topic as solved.

My first attempts to fix my custom camera implementation has brought back in the stuttering as it appears that the camera follow is somewhat fighting against the against the lookat function I have embedded (which maybe shouldn’t be used together: Either that or the stuttering isn’t there and the camera is either looking at the player from a static position or being so slow to catch up its rotation that the camera goes so far as flipping as it tries to go above the player.

public class CameraFollow : MonoBehaviour
{
[SerializeField]
Transform playerTransform;

[SerializeField]
float yDistance, zDistance, sensitivity;


// Start is called before the first frame update
void Start()
{
    transform.position = playerTransform.position - new Vector3(-yDistance, zDistance);
    transform.LookAt(playerTransform.transform);
}

// Update is called once per frame
void Update()
{
    
    //transform.position = Vector3.Lerp(transform.position, playerTransform.position - new Vector3(0, -yDistance, zDistance),sensitivity);
    //transform.LookAt(playerTransform.transform);
}

private void LateUpdate()
{
    transform.position = Vector3.Lerp(transform.position, playerTransform.position - new Vector3(0, -yDistance, zDistance), sensitivity);
    transform.LookAt(playerTransform.transform);
}

}

The cinemachine seems to be working fine (at least when follow or look at are indivisually pointed at the player transform), but again I will check when I have access to my desktop.

You implemented the cinemachine yourself in this project, didn’t you? If so, for what do you need the CameraFollow script? It might be that the code in that script is overriding the values the cinemachine generated, and vice versa.

Remove the CameraFollow component and test your project with the cinemachine only.

I test each of them separately. Tend to be hesitant to rely on a black box without having some basic understanding of how to get things working myself - and I figured I would need to spend significantly more time in the cinemachine documentation to get an understanding of how to achieve the effects I desire reliably in the case of this one-off.

How to make the camera follow an object in Unity3D - codinBlack

Anyways after searching up the issue, I found an article that helped me resolve the issue I was looking at in terms of having a camera follow that had smoothness to it and provided camera rotation reliably adding movement to the player’s view.

I’ll spend more time with cinemachine docs as I go forward - initially when I tried playing with it I was getting all kinds of weird results. I’ll probably stick to my updated code until I have a good understanding of it.

Thanks a lot for sharing what you figured out. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms