Hello,
I’ve struggled with this problem for over a year, and now, nearing the end of the production cycle of our commercial game, I’m out of time and ideas.
For the life of me, I cannot smoothly move a 2D camera from one end of the screen to the other without ghosting.
Here’s a simple code sample that shows the problem:
using UnityEngine;
using System.Collections;
public class SmoothScroll : MonoBehaviour {
[SerializeField]
private float speed = 800.0f;
private Vector3 position;
private float screenRadius;
private void Awake () {
Application.targetFrameRate = 60;
this.position = new Vector3 ();
this.screenRadius = this.camera.orthographicSize * this.camera.aspect;
}
private void Update () {
this.position = this.transform.position;
this.position.x += this.speed * Time.deltaTime;
if (this.position.x > this.screenRadius)
this.position.x = - this.screenRadius;
this.transform.position = this.position;
}
}
The target platform is iOS, but the problem remains the same in standalone MacOS and Windows. Here’s a list of things I’ve tried:
- Could be a response time issue, tried multiple screens.
- Could be a vsync issue, tried turning it on, turning it off, setting it for every second blank.
- Changed Application.targetFrameRate to 60, 30 and disabled.
- Tried different types of movement, setting position directly, using translate, changing it on update, fixed update, late update, using Time.deltaTime, using Time.smoothDeltaTime, ignoring deltaTime completely (obviously, that last one was the worst)
- Tried without a rigidbody, rigidbody with interpolation, and rigidbody with extrapolation
- Tried moving the camera while the objects are still, tried moving the objects while the camera is still
- Tried all settings of anti-alias
- Could be distortion from stretching, so I tried having a pixel-perfect orthographic camera
- Could be a floating point precision problem, so I tried using only rounded integer positions on a pixel-perfect camera (grasping at straws here)
- Tried multiple combinations of the previous points
Nothing seems to work. I’ve been all over the web this past year searching for solutions for this problem, and I’ve come up empty.
Here’s a demo, with the same code as above, that shows the problem (MacOS and Windows standalone builds).