Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class CameraFollow : MonoBehaviour
- {
- public Transform target; // Reference to the player character
- public Vector3 offset = new Vector3(0, 0, -10); // Offset to maintain distance
- public float smoothSpeed = 0.125f; // Smoothing factor for the follow movement
- private void LateUpdate()
- {
- if (target != null)
- {
- // Calculate the desired position with offset
- Vector3 desiredPosition = target.position + offset;
- // Smoothly interpolate the camera’s position to the target position
- Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
- // Set the camera’s position
- transform.position = smoothedPosition;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement