30 lines
917 B
C#
30 lines
917 B
C#
using KBCore.Refs;
|
|
using UnityEngine;
|
|
|
|
namespace Infrastructure.Unity
|
|
{
|
|
public class CameraController : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform target;
|
|
[SerializeField] private Vector3 offset = new(-20, 20, -20);
|
|
[SerializeField] private float smoothSpeed = 5f;
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (!target) return;
|
|
|
|
// We follow the player, but we might want to clamp X/Z movement
|
|
// so the camera doesn't jitter too much, only tracking Y (falling).
|
|
// For a dynamic feel, let's track everything loosely.
|
|
|
|
var desiredPos = target.position + offset;
|
|
|
|
transform.position = Vector3.Lerp(transform.position, desiredPos, Time.deltaTime * smoothSpeed);
|
|
}
|
|
|
|
public void SetTarget(Transform newTarget)
|
|
{
|
|
target = newTarget;
|
|
}
|
|
}
|
|
} |