- Home /
Camera smooth follow behaviour
Hello everybody, I am struggling to get a camera to smoothly follow a transform, I hope you can help me!
My current setup is that I have a dummy empty GameObject called CameraPosition following the transform, without any damping applied. Then, I have a Camera GameObject which tries to match CameraPosition's transform, while smoothing out its movement. This is what I got:
using UnityEngine;
public class PositionFollower : MonoBehaviour
{
[SerializeField] private Transform Target;
[SerializeField] private float Speed = 10;
protected virtual void Update()
{
transform.position = Vector3.Lerp(transform.position, Target.position, Speed * Time.deltaTime);
transform.rotation = Quaternion.Slerp(transform.rotation, Target.rotation, Speed * Time.deltaTime);
}
}
Smoothing kind of works, but not really how I want: movement only smoothes out. If I were to plot a graph with time on the x-axis, and speed on the y-axis, I would get:
What I want is however something like this (both the red and orange graph are OK for me; also notice that speed reaches 0 again after exactly D units of time):
TL;DR: I'd like Object1 to follow Object2, smoothing movement in and out, and I want Object1 to take no more and no less that D seconds to reach Object2 every time it moves. How can I accomplish this?
Your answer
Follow this Question
Related Questions
Smooth camera script looking at left hand side of character. 0 Answers
Resetting Camera with a key input 1 Answer
Returning the camera back to original position, 1 Answer
Camera View Problem 0 Answers