This issue has been haunting me for days, and I hope some one could rescue me!
The issue is simple, I have a huge image and I want the camera to move horizontally across the image (which takes 10 seconds), however, in both methods I use to move the camera, there are always some stutters/jitters during the movement:
1. Method 1 - translate each frame using Time.DeltaTime (no rb2D attached to camera):
// Update is called once per frame
void Update () {
Camera.main.transform.position = new Vector3 (Camera.main.transform.position.x + moveSpeed * Time.deltaTime, Camera.main.transform.position.y,Camera.main.transform.position.z);
}
2. Method 2 - attach a rigidbody2D to the camera, and set the x velocity of the camera to a moveSpeed (e.g. 10f) at “Start()”
I do no get how the movement is jittery in both methods, since both methods should have corrected the timesteps/framerate issues? Have I used the wrong way to move the camera? Any settings for me to avoid the problem?
Thanks very much!
anyone could solve my issue? Or is it true that it is impossible for Unity to create jitterless movement?
Well, not sure. Usually posts about jitter have to do with more gameplay like stuff.
Anyhow, I would cache the Transform of the camera and update that (instead of Camera.main.transform…)
I would try building it and see how it looks then to see if there is some difference between the editor.
If other things are also moving, and may contribute to the jitter, I would move the camera’s movement to LateUpdate
My suggestions are for the transform being moved, not the rigidbody.
You could also use the profiler to see if anything stands out.
Try calling the code in LateUpdate() instead.
Thanks for suggestions, but I think those are not related to LateUpdate, as nothing in the scene moves during each frame - the only thing that moves is the camera
If you are moving something with RigidBodies (i.e., the physics) and tracking it with a camera, you must update your camera not on Update(), not on LateUpdate(), but rather you must use FixedUpdate() to update the camera position.
I’m assuming that this applies to RigidBody2Ds as well. Give it a whirl.
EDIT: Oops,sorry, I think I misread your post. Try building it to your target platform (Windows or Mac) and see if it is smoother as a standalone app. Particularly some Windows versions of the Unity editor can act chuggy, depending on what else you have going on your system.