diff --git a/Assets/Scripts/CubeClash/CubeClash_CubeLid.cs b/Assets/Scripts/CubeClash/CubeClash_CubeLid.cs index 9074ccb..4708a15 100644 --- a/Assets/Scripts/CubeClash/CubeClash_CubeLid.cs +++ b/Assets/Scripts/CubeClash/CubeClash_CubeLid.cs @@ -171,13 +171,19 @@ public class CubeClash_CubeLid : MonoBehaviour } // ====== Gameplay ====== + [Header("Spring Animation")] + [Tooltip("How high the cube jumps visually when launching a player.")] + public float springHeight = 0.5f; + [Tooltip("How long the up and down tween takes (seconds).")] + public float springDuration = 0.2f; + + + [ContextMenu("Activate Lid")] private void ActivateLid() { - // Overlap volume GetOverlapBoxWorld(out Vector3 center, out Vector3 halfExtents, out Quaternion orientation); Collider[] cols = Physics.OverlapBox(center, halfExtents, orientation, detectMask, triggerQuery); - // Build camera-relative forward dir from inspector vector Vector3 worldForward = GetCameraRelativeDirection(camSpaceDir, flattenCamera); foreach (Collider col in cols) @@ -185,13 +191,30 @@ public class CubeClash_CubeLid : MonoBehaviour if (!col) continue; if (col.CompareTag("Zibu") && col.attachedRigidbody != null) { - // Up + camera-relative forward Vector3 impulse = (Vector3.up * launchForce) + (worldForward * (launchForce * forwardScale)); col.attachedRigidbody.AddForce(impulse, ForceMode.Impulse); } } + + // --- NEW spring animation --- + DoSpringAnimation(); } + private void DoSpringAnimation() + { + // kill any existing spring + DOTween.Kill("CubeSpring_" + GetInstanceID()); + + Vector3 startPos = transform.position; + Vector3 upPos = startPos + Vector3.up * springHeight; + + Sequence seq = DOTween.Sequence(); + seq.Append(transform.DOMoveY(upPos.y, springDuration).SetEase(Ease.OutQuad)); + seq.Append(transform.DOMoveY(startPos.y, springDuration).SetEase(Ease.InQuad)); + seq.SetId("CubeSpring_" + GetInstanceID()); + } + + private static Vector3 GetCameraRelativeDirection(Vector2 camDir, bool flatten) { Transform cam = Camera.main ? Camera.main.transform : null;