Camera Stutter

In this example I have experienced a camera stuttering while my camera moves. I also wondered if this was going to happen with a simpler scene, so I created a very basic scene with 1 very long backgroud 1 moving cube and 1 following camera I used camera script to follow. But the problem was still there. I tried solve my problem for 2 days but I wasnt able to then after lots of researches I’ve gathered couple of useful information which I list here : I turned off my vSync, adjusted my ball’s rigidbody to interpolate and in the time settings I set my fixedtime to 0.0001 and now it doesnt stutter it works so smooth. Set my AA to 4x . I find this useful too http://www.kinematicsoup.com/news/2016/8/9/rrypp5tkubynjwxhxjzd42s3o034o8 . My concern is that I dont know if setting fixed time to very low would cause any problems regarding to unity physics since it relies on that?​ I already tried all different update combinations with my ball and camera (setting them with different update functions like update-update, update-lateupdate, fixedupdate-lateupdate etc.) none of them worked. Changing fixed time was the most perceived one and closing vSync was the second. Thanks for any advice

1 Like

Hello @ehturan, how are you?
Tweaking the fixeddeltatime is not a good fix for this problem, it will slow down the game performance by a lot, it is only recommend to change this setting when there are a lot of fast moving objects in the scene interacting with each other.
Can you share your code responsible for moving the camera? The problem is probably there.
Can you give further explanation regarding the problem too? It may help

Thanks for your reply. I realized that my camera stuttering issue is not limited to this project only. As I said I opened new project with 1 camera 1 moving object and the camera following it. The problem that occurs looks like this (This is not my project but the problem is same) http://www.skgames.net/wp-content/uploads/2013/10/Unity_4_2_2_Stuttering.mov Although I didnt record this shot, my problem is exactly the same. You can read full thread here a lot of people having the same issue but no reply unfortunately. https://forum.unity3d.com/threads/stuttering-issue-on-unity-4-2.203552/ I have tried with both unity 5.2 and 2017.1 but no luck. The results are the same. vsync was affectting me a lot but even turning it off didnt help much but decreasing fixed tim e made it sooooo smuth as i expected I found that from here https://www.youtube.com/watch?v=sDwV5trhiXI . The problem that this guy shows somewhat similar to mine but as i said my problem is exactly same as the first one. I have been trying to figure this out for 5 days but :confused: I dont know what to do. I believe my codes are not the problem since the code is only 1-2 line but if you wonder here it is : (This is for the basic project only camera following a moving object on x direction with a tiled background (in order to see if the camera stutters or not))

public class MovingObjectScript : MonoBehaviour {

public static MovingObjectScript instance;

[SerializeField]
private Rigidbody2D myRigidBody;

[SerializeField]
private Animator anim;

private float forwardSpeed = 2f;

void Start()
{
	SetCameraX();
}

void FixedUpdate ()
{
		Vector3 temp = transform.position;
		temp.x += forwardSpeed * Time.deltaTime;
		transform.position = temp;
}

void SetCameraX()
{
	CameraScript.offsetX = (Camera.main.transform.position.x - transform.position.x) - 1f;
}

public float GetPositionX()
{
	return transform.position.x;
}

This is for the moving object.

And this is for the camera

public class CameraScript : MonoBehaviour
{
public static float offsetX;

void Update ()
{
			MoveTheCamera();
}

void MoveTheCamera()
{
	Vector3 temp = transform.position;
	temp.x = MovingObjectScript.instance.GetPositionX() + offsetX;
	transform.position = temp;
}
}

Besides this I have tried to get the old position in the update and carrying to the new position in late update it gives a slightly better smoothness. Using fixed time with a value of 0.02 makes it horrible (The stutter is so obvious when its 0.02). Using only update with 0.02 still bad. I am about eat my brain because of this error. I want to solve this permanently without changing fixed steps. If someone can help me solving this problem. I will pray for him/her :smiley: (All this made with without vsync. When I turn it on it goes really bad and even decreasing timesteps dont help it)

You are using the fixedupdate to update the object movement and the update to change the camera position. I think that it is better to stick to only one of those. This problem probably is happening because the loop events are happening in the wrong order and using different events, also, you are using Time.deltaTime within an FixedUpdate method (you don’t need to use it here).

A possible fix for this problem is to call the MoveTheCamera method within the MovingObjectScript at the end of your FixedUpdate block instead of using a CameraScript just for that. Try taking out the Time.deltaTime too.

Privacy & Terms