Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion Modules/BilliardsModule/UdonScripts/BilliardsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down