I’ve been researching this for about two weeks and have come across nothing that works. Anything will be helpful!
This works really nice for me. You can also find it on official unity documentation page.
// Smooth towards the target
using UnityEngine;
using System.Collections;
public class DampCamera2D : MonoBehaviour
{
public Transform target;
public float smoothTime = 0.3F;
private Vector3 velocity = Vector3.zero;
void Update()
{
// Define a target position above and behind the target transform
Vector3 targetPosition = target.TransformPoint(new Vector3(0, 5, -10));
// Smoothly move the camera towards that target position
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
}
}
I usually go with something i can tweak in editor i set the right position in editor and voilla this helps lerp camera in place nicely:
public Transform target;
public Vector3 target_Offset;
private void Start()
{
target_Offset = transform.position - target.position;
}
void Update()
{
if (target)
{
transform.position = Vector3.Lerp(transform.position, target.position+target_Offset, 0.1f);
}
}`
install the standard assets with Unity. there’s a follow script packed along with it
Here’s a real simple follow camera script:
public Transform target;
void Update()
{
if (target)
{
transform.position = Vector3.Lerp (transform.position, target.position, 0.1f);
}
}
}
Just put the script on the Camera and in the Inspector set the target to be the main gameobject.
maybe this will help
You should not be moving camera in update, you should be moving it in lateupdate
You can just use Unity’s package Cinemachine for really smooth, simple, and professional camera tracking and other things! It’s really useful and great. Just go to the top Window > Package Manager and search for cinemachine there.