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); } } }
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
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 }
} // 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
void Start() { callBall = FindObjectOfType <billiardBall>(); }