- Home /
Lerp/slerp to smooth camera
Hello. I'm trying to make a smoother camera to my over the shoulder shooter. My idea was quite simply to use Lerp or Slerp between the cameras current rotation and the characters rotation.
However, my script doesn't seem to do anything at all. The camera is basically bolted to the character rotation, and regardless what value I give the speed variable, that doesn't seem to change. This is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SmoothCameraScript : MonoBehaviour {
public Transform Protagonist;
public Transform Camera;
public float speed;
public Text Debug;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Camera.rotation = Quaternion.Slerp (Camera.rotation, Protagonist.rotation, Time.deltaTime* speed);
Debug.text = "Camera: " + Camera.rotation.ToString () + "\nPlayer: " + Protagonist.rotation.ToString ();
}
}
Any thoughts?
Are you sure you attached the right Camera to public Transform Camera; ? Because code have to work, if you correctly find Protagonist, and Camera gameobjects.
I'm sure. Is it perhaps a problem that the camera is a child of the character?
Answer by Hogge · Jun 16, 2018 at 03:32 PM
The solution I came up with myself was to make the camera a seperate object rather than a child of the main character, which solved the problem.