From 78dea3d0b65e2979349de08bf70324bfc9cd2459 Mon Sep 17 00:00:00 2001 From: eijis-pan Date: Fri, 31 Oct 2025 16:04:31 +0900 Subject: [PATCH] =?UTF-8?q?9Ball=20=E3=82=92=E3=83=86=E3=83=BC=E3=83=96?= =?UTF-8?q?=E3=83=AB=E3=81=AB=E6=88=BB=E3=81=99=E5=A0=B4=E5=90=88=E3=81=AB?= =?UTF-8?q?=E3=80=81=E5=88=A5=E3=81=AE=E3=83=9C=E3=83=BC=E3=83=AB=E3=81=8C?= =?UTF-8?q?=E3=81=82=E3=82=8B=E3=81=A8=E9=9A=99=E9=96=93=E3=81=8C=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=20----=20When=20returning=20a=209-ball=20to?= =?UTF-8?q?=20the=20table,=20another=20ball=20may=20create=20a=20gap.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UdonScripts/BilliardsModule.cs | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Modules/BilliardsModule/UdonScripts/BilliardsModule.cs b/Modules/BilliardsModule/UdonScripts/BilliardsModule.cs index 3662c07..2e2557a 100644 --- a/Modules/BilliardsModule/UdonScripts/BilliardsModule.cs +++ b/Modules/BilliardsModule/UdonScripts/BilliardsModule.cs @@ -1677,7 +1677,7 @@ public void _TriggerSimulationEnded(bool forceScratch, bool forceRun = false) ballsPocketedLocal = ballsPocketedLocal & ~(0x200u); ballsP[9] = initialPositions[1][9]; //keep moving ball down the table until it's not touching any other balls - moveBallInDirUntilNotTouching(9, Vector3.right * .051f); + moveBallXUntilNotTouching(9); } } else if (is4Ball) @@ -1966,6 +1966,39 @@ private void moveBallInDirUntilNotTouching(int Ball, Vector3 Dir) ballsP[Ball] += Dir; } } + private void moveBallXUntilNotTouching(int Ball) + { + float ballDiameter = k_BALL_RADIUS * 2f; + float k_BALL_DSQR = ballDiameter * ballDiameter; + float threshold = 0.0001f; + int adjustCount = 0; + + //keep moving ball down the table until it's not touching any other balls + int touchingBall = -1; + int prevTouchingBall = -1; + while ((touchingBall = CheckIfBallTouchingBall(Ball)) > -1) + { + if (prevTouchingBall == touchingBall) + { + adjustCount++; + } + else + { + adjustCount = 0; + } + + float distanceZ_DSQR = ballsP[touchingBall].z * ballsP[touchingBall].z; + float adjustX = Mathf.Sqrt(k_BALL_DSQR - distanceZ_DSQR); + ballsP[Ball] = new Vector3 + ( + ballsP[touchingBall].x + adjustX + (threshold * adjustCount), + ballsP[Ball].y, + ballsP[Ball].z + ); + + prevTouchingBall = touchingBall; + } + } private int CheckIfBallTouchingBall(int Input) { float ballDiameter = k_BALL_RADIUS * 2f;