Add initial project files and configurations for Unity setup
This commit is contained in:
30
Assets/Scripts/Infrastructure/Unity/CameraController.cs
Normal file
30
Assets/Scripts/Infrastructure/Unity/CameraController.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user