@@ -2897,7 +2897,7 @@ public void _TriggerSimulationEnded(bool forceScratch, bool forceRun = false)
28972897 otherPocketedLocal = otherPocketedLocal & ~ ( 0x2U ) ;
28982898#endif
28992899 ballsP [ 1 ] = initialPositions [ 1 ] [ 1 ] ; //初始点
2900- moveBallInDirUntilNotTouching ( 1 , Vector3 . right * .051f ) ;
2900+ moveBallXUntilNotTouching ( 1 ) ;
29012901 }
29022902 if ( is8Sink && colorTurnLocal ) BreakFinish = true ;
29032903 else BreakFinish = false ;
@@ -2928,12 +2928,6 @@ public void _TriggerSimulationEnded(bool forceScratch, bool forceRun = false)
29282928 isOpponentSink = false ;
29292929 }
29302930
2931- if ( is8Sink && ( pushOut || ( isOnBreakShot && ! winCondition && deferLossCondition ) ) )
2932- {
2933- moveBallInDirUntilNotTouching ( 9 , Vector3 . right * .051f ) ;
2934- deferLossCondition = false ;
2935- }
2936-
29372931 if ( isOnBreakShot && isAnyPocketSink )
29382932 {
29392933 isObjectiveSink = true ;
@@ -3087,9 +3081,9 @@ public void _TriggerSimulationEnded(bool forceScratch, bool forceRun = false)
30873081 targetPocketedLocal = targetPocketedLocal & ~ ( gameBallMask ) ;
30883082 otherPocketedLocal = otherPocketedLocal & ~ ( gameBallMask ) ;
30893083#endif
3090- ballsP [ gameBallId ] = initialPositions [ gameModeLocal ] [ gameBallId ] ;
3084+ ballsP [ gameBallId ] = initialPositions [ gameModeLocal ] [ is9Ball ? gameBallId : 2 ] ;
30913085 //keep moving ball down the table until it's not touching any other balls
3092- moveBallInDirUntilNotTouching ( gameBallId , Vector3 . right * .051f ) ;
3086+ moveBallXUntilNotTouching ( gameBallId ) ;
30933087 }
30943088#else
30953089 // Win condition: Pocket 9 ball ( and do not foul )
@@ -3103,7 +3097,7 @@ public void _TriggerSimulationEnded(bool forceScratch, bool forceRun = false)
31033097 ballsPocketedLocal = ballsPocketedLocal & ~ ( 0x200u ) ;
31043098 ballsP [ 9 ] = initialPositions [ 1 ] [ 9 ] ;
31053099 //keep moving ball down the table until it's not touching any other balls
3106- moveBallInDirUntilNotTouching ( 9 , Vector3 . right * .051f ) ;
3100+ moveBallXUntilNotTouching ( 9 ) ;
31073101 }
31083102#endif
31093103#if EIJIS_CALLSHOT
@@ -3663,6 +3657,39 @@ private void moveBallInDirUntilNotTouching(int Ball, Vector3 Dir)
36633657 ballsP [ Ball ] += Dir ;
36643658 }
36653659 }
3660+ private void moveBallXUntilNotTouching ( int Ball )
3661+ {
3662+ float ballDiameter = k_BALL_RADIUS * 2f ;
3663+ float k_BALL_DSQR = ballDiameter * ballDiameter ;
3664+ float threshold = 0.0001f ;
3665+ int adjustCount = 0 ;
3666+
3667+ //keep moving ball down the table until it's not touching any other balls
3668+ int touchingBall = - 1 ;
3669+ int prevTouchingBall = - 1 ;
3670+ while ( ( touchingBall = CheckIfBallTouchingBall ( Ball ) ) > - 1 )
3671+ {
3672+ if ( prevTouchingBall == touchingBall )
3673+ {
3674+ adjustCount ++ ;
3675+ }
3676+ else
3677+ {
3678+ adjustCount = 0 ;
3679+ }
3680+
3681+ float distanceZ_DSQR = ballsP [ touchingBall ] . z * ballsP [ touchingBall ] . z ;
3682+ float adjustX = Mathf . Sqrt ( k_BALL_DSQR - distanceZ_DSQR ) ;
3683+ ballsP [ Ball ] = new Vector3
3684+ (
3685+ ballsP [ touchingBall ] . x + adjustX + ( threshold * adjustCount ) ,
3686+ ballsP [ Ball ] . y ,
3687+ ballsP [ Ball ] . z
3688+ ) ;
3689+
3690+ prevTouchingBall = touchingBall ;
3691+ }
3692+ }
36663693 private int CheckIfBallTouchingBall ( int Input )
36673694 {
36683695 float ballDiameter = k_BALL_RADIUS * 2f ;
0 commit comments