Improve smooth 2d side scroller camera to look more fluent

Hi,

I am using a very simple linear interp camera with the key lines being

    Vector3 newPos = target.position + new Vector3(0, relativeHeigth, -zDistance);
    transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * dampSpeed);

(this is from the camera script of the marble game in 5 Unity game examples: C#). This works beatifully for a slow paced game, but in my case velocities are a bit higher (often rigidbody.velocity.magnitude reaches 20 under normal scalings) and when the game is fast my marble doesn’t look sharp but its edges seem to be unsteady. If I change the script to a primitive

this.transform.position = new Vector3(target.transform.position.x, this.transform.position.y, this.transform.position.z);

then the edges look much sharper (but obviously the smooth following of the camera is gone).

Any ideas how in the smooth script the unsteadiness of the edges can be approached?

Best,
Instability

I had a similar problem with scrolling ‘smoothness’ myself. My code that I had written was as follows (make sure to read the note below after the code):

public GameObject player;

// Use this for initialization
void Start () {
    
}

// Update is called once per frame
void Update () {

    Vector3 offset = transform.position - player.transform.position;

    bool changeInX = false;
    bool changeInY = false;

    Vector3 newCameraPosition = transform.position;

    if (offset.x > 3)
    {
        changeInX = true;
        newCameraPosition.x = (player.transform.position.x + offset.x) - (offset.x - 3);
    }
    else if (offset.x < -3)
    {
        changeInX = true;
        newCameraPosition.x = (player.transform.position.x + offset.x) - (offset.x + 3);
    }

    if (offset.y > 2)
    {
        changeInY = true;
        newCameraPosition.y = (player.transform.position.y + offset.y) - (offset.y - 2);
    }
    else if (offset.y < -2)
    {
        changeInY = true;
        newCameraPosition.y = (player.transform.position.y + offset.y) - (offset.y + 2);
    }

    if (!changeInX)
    {
        newCameraPosition.x = transform.position.x;
    }

    if (!changeInY)
    {
        newCameraPosition.y = transform.position.y;
    }

    transform.position = newCameraPosition;

}

The thing that I did which fixed it to smooth scrolling was to change the void Update() function to a void LateUpdate() function. Once I did that, the scrolling was much more smooth! Hope this helps :slight_smile: