Files
Ipseity-Demo/Assets/_Content/Scripts/Features/LiminalSpaces/HouseOfLeaves/Runtime/SandTerrainController.cs
T

76 lines
3.4 KiB
C#

using UnityEngine;
namespace Unheimlich.World.HouseOfLeaves
{
/// <summary>
/// Animates the sand terrain rising from below the corridor floor
/// based on the player's progression through the corridor.
///
/// The terrain starts buried underground and slowly emerges as the
/// player advances, simulating sand flooding the corridor from below.
/// </summary>
public class SandTerrainController : MonoBehaviour
{
// ─────────────────────────────────────────────────────────────────────────
// Serialized Fields
// ─────────────────────────────────────────────────────────────────────────
[Header("References")]
[Tooltip("The HouseOfLeavesController driving the progression value.")]
[SerializeField] private HouseOfLeavesController _controller;
[Tooltip("The sand terrain Transform to animate.")]
[SerializeField] private Transform _sandTerrain;
[Header("Rise Settings")]
[Tooltip("Y position of the terrain at the start (buried underground).")]
[SerializeField] private float _startY = -4f;
[Tooltip("Y position of the terrain at full progression (emerged).")]
[SerializeField] private float _endY = 0.5f;
[Tooltip("Lerp speed applied to the vertical movement each frame.")]
[SerializeField] private float _lerpSpeed = 2f;
[Tooltip("Animation curve mapping progression [0,1] to rise amount [0,1]. " +
"Use this to delay the rise until mid-corridor for example.")]
[SerializeField] private AnimationCurve _riseCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
// ─────────────────────────────────────────────────────────────────────────
// Unity Messages
// ─────────────────────────────────────────────────────────────────────────
private void Start()
{
if (_controller == null)
{
Debug.LogError("[SandTerrainController] HouseOfLeavesController reference is missing.");
return;
}
if (_sandTerrain == null)
{
Debug.LogError("[SandTerrainController] Sand terrain Transform is missing.");
return;
}
// Initialize position immediately without lerp.
Vector3 startPos = _sandTerrain.position;
startPos.y = _startY;
_sandTerrain.position = startPos;
}
private void Update()
{
if (_controller == null || _sandTerrain == null) return;
float t = _riseCurve.Evaluate(_controller.Progression);
float targetY = Mathf.Lerp(_startY, _endY, t);
Vector3 pos = _sandTerrain.position;
pos.y = Mathf.Lerp(pos.y, targetY, Time.deltaTime * _lerpSpeed);
_sandTerrain.position = pos;
}
}
}