Compare commits
No commits in common. "acb6b0a30ce578504caa4c78905a2be8b3f1918f" and "abdc13c20f257212780ff4df09edd2db84a91acd" have entirely different histories.
acb6b0a30c
...
abdc13c20f
@ -171,19 +171,13 @@ 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)
|
||||||
@ -191,30 +185,13 @@ 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