Smooth a camera

Hey there, i would like to make the camera i am currently working with, follow the target GameObjcet smoothly.

This is the script i have at the moment.

using UnityEngine;
using System.Collections;

/*
 * 
 * Author Christoffer "Dakk" Krook
 * 
 * */

public class UsedCameraScript : MonoBehaviour {
	
	public Transform target;
	
	private float currentXAngle = 43;
	private float currentYAngle = 0;
	private float currentZAngle = 0;
	
	private float currentXPos = 0f;
	private float currentYPos = 0f;
	private float currentZPos = 0f;
	
	
	
	// Use this for initialization
	void Start () {
		currentXPos = transform.position.x;
		currentYPos = transform.position.y;
		currentZPos = transform.position.z;
	}
	
	// Update is called once per frame
	void Update () {
		currentXPos += target.transform.position.x;
		currentYPos += target.transform.position.y;
		currentZPos += target.transform.position.z;
		
		
		//Flyttar kameran så att den sitter där den ska. Den följer skarpt i Xled men inte i Zled. Yled rörs ej.
		transform.position = new Vector3(target.transform.position.x, target.transform.position.y+3.7f, target.transform.position.z/2-8.5f);
		transform.eulerAngles = new Vector3(currentXAngle, currentYAngle, currentZAngle);
	}
}

And it follows a GameObject sharply on the X axis and a little less sharp on the zAxis. Could someone here teach me how i could make it a little smoother on the x as well as a the z axis.

Try to use:
transform.rotation = Quaternion.Slerp (from.rotation, to.rotation, Time.time * speed);

Is a function to get a smothly rotation change. I think that exists too a function to a smoth position change, but I never used.
Is a bit difficult at least for me, but if you don’t know how to use this function, i can help you some more.

The rotation should be locked. It is the POSITION i would want to move smoothly.

Then, i think you can use
transform.position = Vector3.Lerp(start.position, end.position, Time.time);

I tried it. It did not work. It was spazzing like crazy.

:frowning: I will study this night how it works

I somved it. I rewrote the script and lerpee etc. Thanks for your concern :slight_smile: