Compare commits
2 Commits
abdc13c20f
...
acb6b0a30c
Author | SHA1 | Date | |
---|---|---|---|
acb6b0a30c | |||
f33cf0e367 |
@ -171,13 +171,19 @@ public class CubeClash_CubeLid : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ====== Gameplay ======
|
// ====== 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()
|
private void ActivateLid()
|
||||||
{
|
{
|
||||||
// Overlap volume
|
|
||||||
GetOverlapBoxWorld(out Vector3 center, out Vector3 halfExtents, out Quaternion orientation);
|
GetOverlapBoxWorld(out Vector3 center, out Vector3 halfExtents, out Quaternion orientation);
|
||||||
Collider[] cols = Physics.OverlapBox(center, halfExtents, orientation, detectMask, triggerQuery);
|
Collider[] cols = Physics.OverlapBox(center, halfExtents, orientation, detectMask, triggerQuery);
|
||||||
|
|
||||||
// Build camera-relative forward dir from inspector vector
|
|
||||||
Vector3 worldForward = GetCameraRelativeDirection(camSpaceDir, flattenCamera);
|
Vector3 worldForward = GetCameraRelativeDirection(camSpaceDir, flattenCamera);
|
||||||
|
|
||||||
foreach (Collider col in cols)
|
foreach (Collider col in cols)
|
||||||
@ -185,13 +191,30 @@ public class CubeClash_CubeLid : MonoBehaviour
|
|||||||
if (!col) continue;
|
if (!col) continue;
|
||||||
if (col.CompareTag("Zibu") && col.attachedRigidbody != null)
|
if (col.CompareTag("Zibu") && col.attachedRigidbody != null)
|
||||||
{
|
{
|
||||||
// Up + camera-relative forward
|
|
||||||
Vector3 impulse = (Vector3.up * launchForce) + (worldForward * (launchForce * forwardScale));
|
Vector3 impulse = (Vector3.up * launchForce) + (worldForward * (launchForce * forwardScale));
|
||||||
col.attachedRigidbody.AddForce(impulse, ForceMode.Impulse);
|
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)
|
private static Vector3 GetCameraRelativeDirection(Vector2 camDir, bool flatten)
|
||||||
{
|
{
|
||||||
Transform cam = Camera.main ? Camera.main.transform : null;
|
Transform cam = Camera.main ? Camera.main.transform : null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user