diff --git a/Packages/com.vrcbilliards.vrcbce/Runtime/Scripts/BasePoolStateManager.cs b/Packages/com.vrcbilliards.vrcbce/Runtime/Scripts/BasePoolStateManager.cs index 9850dec..116134c 100644 --- a/Packages/com.vrcbilliards.vrcbce/Runtime/Scripts/BasePoolStateManager.cs +++ b/Packages/com.vrcbilliards.vrcbce/Runtime/Scripts/BasePoolStateManager.cs @@ -1850,6 +1850,9 @@ private void OnLocalTurnStart() { ResetTimer(); } + + // sanitize old cue tip location data to prevent stale data from causing unintended effects. + localSpacePositionOfCueTipLastFrame = tableSurface.transform.InverseTransformPoint(cueTip.transform.position); } private void OnNewGameStarted() @@ -3303,4 +3306,4 @@ private void PlayAudioClip(AudioClip clip) mainSrc.PlayOneShot(clip); } } -} \ No newline at end of file +} diff --git a/Packages/com.vrcbilliards.vrcbce/Runtime/Scripts/PoolStateManager.cs b/Packages/com.vrcbilliards.vrcbce/Runtime/Scripts/PoolStateManager.cs index d7b13ac..6203f51 100644 --- a/Packages/com.vrcbilliards.vrcbce/Runtime/Scripts/PoolStateManager.cs +++ b/Packages/com.vrcbilliards.vrcbce/Runtime/Scripts/PoolStateManager.cs @@ -328,7 +328,7 @@ protected override void HitBallWithCue(Vector3 shotDirection, float velocity) float a = jkPlane.GetDistanceToPoint(Q); float b = Q.y - o.y; - float c = Mathf.Sqrt(Mathf.Pow(ballRadius, 2) - Mathf.Pow(a, 2) - Mathf.Pow(b, 2)); + float c = Mathf.Sqrt(Mathf.Max(0,Mathf.Pow(ballRadius, 2) - Mathf.Pow(a, 2) - Mathf.Pow(b, 2))); float adj = Mathf.Sqrt(Mathf.Pow(q.x, 2) + Mathf.Pow(q.z, 2)); float opp = q.y; @@ -352,7 +352,7 @@ protected override void HitBallWithCue(Vector3 shotDirection, float velocity) // https://billiards.colostate.edu/physics_articles/Alciatore_pool_physics_article.pdf float alpha = -Mathf.Atan( - (5f / 2f * a / ballRadius * Mathf.Sqrt(1f - Mathf.Pow(a / ballRadius, 2))) / + (5f / 2f * a / ballRadius * Mathf.Sqrt(Mathf.Max(0,1f - Mathf.Pow(a / ballRadius, 2)))) / (1 + MASS_OF_BALL / m_e + 5f / 2f * (1f - Mathf.Pow(a / ballRadius, 2))) ) * 180 / Mathf.PI; @@ -1260,4 +1260,4 @@ private void TriggerPocketBall(int id) )); } } -} \ No newline at end of file +}