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!