TO SQUASH: Nuke ball fixes.

This commit is contained in:
2026-08-28 17:44:31 -04:00
parent 7e4b5a2055
commit 716e35c615
10 changed files with 153 additions and 15 deletions
+24 -8
View File
@@ -6,10 +6,12 @@ public class NukeBall : BallBase
public AudioClip explosionSound;
public WorldFiller worldFiller;
// Tracks escalating danger/critical phases for audio cues.
private int criticalState = 0;
private float criticalTime = 1.0f;
private float criticalTime = 0.5f;
private float criticalTimer = 0.0f;
@@ -92,12 +94,16 @@ public class NukeBall : BallBase
transform.position = currentPosition;
}
}
// When in critical state 2, play the critical sound every half a second.
if (criticalState == 2)
{
criticalTimer = 0.5f;
}
void Update()
{
// Set critical state.
var area = worldFiller != null ? worldFiller.GetAreaPercentOfFreeRegion(transform.position) : -1.0f;
criticalState = (area < 0.2f) ? 2 : (area < 0.4f) ? 1 : 0;
// State 1 beeps every 0.5s, state 2 beeps every 0.25s.
criticalTime = (criticalState == 2) ? 0.5f : 1.0f;
// If in a critical state, increment the critical timer and play the
// critical sound if the timer exceeds the critical time.
@@ -108,9 +114,13 @@ public class NukeBall : BallBase
if (criticalTimer >= criticalTime)
{
audioSource.PlayOneShot(criticalSound);
}
// Restart timing window for the next critical beep.
// Keep fractional overflow so cadence stays stable across frame rates.
criticalTimer -= criticalTime;
}
}
else
{
criticalTimer = 0.0f;
}
}
@@ -142,6 +152,12 @@ public class NukeBall : BallBase
currentPosition.y = bounceStartY;
transform.position = currentPosition;
}
else if (contact.normal.y <= -0.5f)
{
isBouncingToHeight = false;
bounceTimer = 0.0f;
height = contact.point.y - 0.01f;
}
}
else
{