Smooth Camera Positioning

Hello, I’m working on writing a script for a camera for a 3D sidescroller. I’m running into a lot of roadblocks with this because I’m fairly new to unity, but not to programming, as I’m a senior student pursuing a degree in software engineering. Anyways:

I found a script, written by Ossadtchii, after browsing the forums that smoothly changes the z-axis on the camera, but refuses to be positioned on a set location. I was wondering if this same concept could be applied to allow a smooth Mathf.Lerp between two different Vector3’s (0, 1, -3) and (0, 2, -7). I’ve tried a number of times to call transform.position, but this transforms the position based on it’s current position, offsetting the camera.

The script I’ve been trying to modify is as follows:

using UnityEngine;
using System.Collections;

public class CameraManager : MonoBehaviour {

    public float distance = -7f;
    private float sensitivity = -7.5f;
    private float damping = 2.5f;
    private float min = -8;
    private float max = -3;
    private Vector3 zdistance;

	// Use this for initialization
        void Start()
        {
        distance = -7f;
        distance = transform.localPosition.z;
	}
	
	// Update is called once per frame
	void Update () 
        {
        distance -= Input.GetAxis("Mouse ScrollWheel") * sensitivity;
        distance = Mathf.Clamp(distance, min, max);
        zdistance.z = Mathf.Lerp(transform.localPosition.z, distance, Time.deltaTime * damping);
        
        transform.localPosition = zdistance;
	}
}

Could somebody just quickly explain that script to me and perhaps offer suggestions on smoothly scrolling between my two Vector3’s?

Thanks in advance!

I suppose what I took from that script was that you CAN zoom your camera via changing the z-axis, rather than using field of view, which most people seem to do.

I’m just looking for help applying the theory to the code, which, in my mind, would be something akin to:

using UnityEngine;
using System.Collections;

public class CameraManager : MonoBehaviour {

    private float damping = 2.5f;
    private Vector3 zoomedIn;
    private Vector3 zoomedOut;


	// Use this for initialization
    void Start()
    {
        zoomedIn = new Vector3(0, 1, -3);
        zoomedOut = new Vector3(0, 2, -7);
    }
	
	// Update is called once per frame
    void Update () 
    {

        //if player is airborn, camera smoothly zooms in
        if (player.isJumping || player.isFalling)
        {
             transform.position = Mathf.Lerp(zoomedIn, zoomedOut, Time.deltaTime * damping);
        }
        //if player is grounded, camera smoothly zooms out
        else
        {
             Mathf.Lerp(zoomedOut, zoomedIn, Time.deltaTime * damping);
        }
    }
}