@@ -198,25 +198,25 @@ private void MoveBalls()
198198
199199 private void MoveBall ( Ball ball , int index )
200200 {
201- float targetDistance = Mathf . Max ( _chainTracker . DistanceTravelled - ( index * _ballChainDto . SpacingBalls ) , 0 ) ;
202- Vector3 targetPosition = _pathCreator . path . GetPointAtDistance ( targetDistance ) ;
201+ float rawTargetDistance = _chainTracker . DistanceTravelled - ( index * _ballChainDto . SpacingBalls ) ;
202+ float targetDistance = Mathf . Clamp ( rawTargetDistance , 0f , _pathCreator . path . length - 0.1f ) ;
203203 float currentSpeed = Time . deltaTime / _ballChainDto . DurationMovingOffset ;
204+
204205 if ( _loseBallChainHandler . IsLose )
205206 {
206- targetPosition = _pathCreator . path . GetPointAtDistance ( _pathCreator . path . length - 0.01f ) ;
207- currentSpeed = Time . deltaTime / ( _ballChainDto . DurationMovingOffset * ( index / 100f ) ) ;
207+ currentSpeed = Time . deltaTime / ( _ballChainDto . DurationMovingOffset + index * 0.03f ) ;
208208 }
209- ball . transform . position = Vector3 . Lerp ( ball . transform . position , targetPosition , currentSpeed ) ;
209+
210+ Vector3 targetPosition = _pathCreator . path . GetPointAtDistance ( targetDistance , EndOfPathInstruction . Stop ) ;
211+ ball . transform . position = Vector3 . Lerp ( ball . transform . position , targetPosition ,
212+ currentSpeed ) ;
213+
210214 }
211215
212216 private void MoveFistBall ( )
213217 {
214- float targetDistance = _chainTracker . DistanceTravelled ;
215- Vector3 targetPosition = _pathCreator . path . GetPointAtDistance ( targetDistance ) ;
216- if ( _loseBallChainHandler . IsLose )
217- {
218- targetPosition = _pathCreator . path . GetPointAtDistance ( _pathCreator . path . length - 0.01f ) ;
219- }
218+ float targetDistance = Mathf . Clamp ( _chainTracker . DistanceTravelled , 0f , _pathCreator . path . length - 0.01f ) ;
219+ Vector3 targetPosition = _pathCreator . path . GetPointAtDistance ( targetDistance , EndOfPathInstruction . Stop ) ;
220220 CurrentBalls [ 0 ] . transform . position = Vector3 . Lerp ( CurrentBalls [ 0 ] . transform . position , targetPosition ,
221221 Time . deltaTime / _ballChainDto . DurationMovingOffset ) ;
222222 }
0 commit comments