Example #1
0
 void Update()
 {
     callBall = FindObjectOfType <billiardBall>();
     foreach (Transform boundary in BoundariesList)
     {
         if (checkCollision(callBall.ballPos, 1.0f, boundary, boundary.localScale / 2))
         {
             callBall.ballVel = getFinalVelocity(boundary, callBall);
         }
     }
 }
Example #2
0
 billiardBall callBall;                               // Calls instance of the ball class
 public static Vector3 getFinalVelocity(Transform boundary, billiardBall callBall)
 {
     return(2 * vectorProjection(boundary, callBall) + callBall.ballVel);
 }                                                                                                                                                       // Calculates where the ball will go after hitting the boundary
Example #3
0
 void Update()
 {
     callBall          = FindObjectOfType <billiardBall>();
     friction          = callBall.ballVel * frictionCoefficient; // The friction is a fraction of the value of the velocity vector
     callBall.ballVel -= friction;                               // the friction is always the opposite direction as the velocity, gradually decreases the velocity
 }
Example #4
0
    }                                                                                                                                                       // Calculates where the ball will go after hitting the boundary

    public static Vector3 vectorProjection(Transform boundary, billiardBall callBall)
    {
        return(dotProduct(callBall.ballVel, getNormalized(boundary)) / Mathf.Pow(vectorMagnitude(getNormalized(boundary)), 2) * getNormalized(boundary));
    }                                                                                                                                                                                                                                   //Calculates the projetion of the ball over the boundary
Example #5
0
 void Start()
 {
     callBall = FindObjectOfType <billiardBall>();
 }