1c6c9b2a70
Add Phase A greybox vertical slice: third-person movement, forest path, checkpoints, story triggers, and light ability gate.
59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace KirbyAdventures
|
|
{
|
|
/// <summary>
|
|
/// Third-person follow camera with mouse look (avoids Cinemachine 3 API coupling).
|
|
/// </summary>
|
|
public class SimpleCameraFollow : MonoBehaviour
|
|
{
|
|
public Transform Target;
|
|
public Transform YawPivot;
|
|
public float Distance = 5.5f;
|
|
public float Height = 1.6f;
|
|
public float MouseSensitivity = 0.12f;
|
|
public float MinPitch = -30f;
|
|
public float MaxPitch = 55f;
|
|
public float Smooth = 12f;
|
|
|
|
float _yaw;
|
|
float _pitch = 12f;
|
|
|
|
public float Yaw => _yaw;
|
|
public float Pitch => _pitch;
|
|
|
|
void Start()
|
|
{
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
Cursor.visible = false;
|
|
if (YawPivot != null)
|
|
_yaw = YawPivot.eulerAngles.y;
|
|
}
|
|
|
|
void LateUpdate()
|
|
{
|
|
if (Target == null) return;
|
|
if (GameFlow.Instance != null && (GameFlow.Instance.IsPaused || GameFlow.Instance.HasWon))
|
|
return;
|
|
|
|
var mouse = Mouse.current;
|
|
if (mouse != null)
|
|
{
|
|
var delta = mouse.delta.ReadValue();
|
|
_yaw += delta.x * MouseSensitivity;
|
|
_pitch -= delta.y * MouseSensitivity;
|
|
_pitch = Mathf.Clamp(_pitch, MinPitch, MaxPitch);
|
|
}
|
|
|
|
if (YawPivot != null)
|
|
YawPivot.rotation = Quaternion.Euler(0f, _yaw, 0f);
|
|
|
|
var rot = Quaternion.Euler(_pitch, _yaw, 0f);
|
|
var desired = Target.position + Vector3.up * Height + rot * (Vector3.back * Distance);
|
|
transform.position = Vector3.Lerp(transform.position, desired, 1f - Mathf.Exp(-Smooth * Time.deltaTime));
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, rot, 1f - Mathf.Exp(-Smooth * Time.deltaTime));
|
|
}
|
|
}
|
|
}
|