Smooth Camera Follow Unity 3D | Unity Tutorial
In this quick tutorial, learn how to create a smooth camera follow effect in Unity 3D. We'll guide you through setting up a camera that smoothly tracks and follows a player character using simple scripting and Unity’s built-in features. Perfect for enhancing your game's camera dynamics and providing a polished player experience!
WATCH FULL TUTORIAL ON YOUTUBE
=========================================================
Unity Projects - ON SALE!!!
1. Water Sort Puzzle 9000 Levels
2. Ball Sort Puzzle 9000 Levels
3. Sling Shot
=========================================================
Script:
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform player; // The player's transform
public Vector3 offset; // Offset position from the player
public float smoothSpeed = 0.125f; // Speed at which the camera follows
void LateUpdate()
{
if (player != null)
{
// Calculate the desired position
Vector3 desiredPosition = player.position + offset;
// Smoothly interpolate between the camera's current position and the desired position
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
// Update the camera's position
transform.position = smoothedPosition;
}
}
}