private static float STOP_BOUNCING_VELOCITY_THRESHOLD = 0.20f;                                                                                                           // The minimum change in net velocity after a bounce without increasing previousNetVelocityCounter


    // Start is called before the first frame update
    void Start()
    {
        // Get the value of OperateCannons.whichCannon
        whichCannon = OperateCannons.whichCannon;

        if (whichCannon == 1) // Correct the angle if the cannonball is from the right cannon
        {
            transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z - 180f);
        }

        cannonballAngle = transform.eulerAngles.z; // Get the cannonball angle

        // Get the initial velocity of the cannonball
        float initial_velocity = (float)OperateCannons.GetSelectedBarrelVelocity();


        // Scale the initial velocity with the velocity factor
        initial_velocity *= VELOCITY_FACTOR;

        // Split the initial velocity into x and y components
        xVelocity = (float)(initial_velocity * System.Math.Cos(ToRadians(cannonballAngle)));
        yVelocity = (float)(initial_velocity * System.Math.Sin(ToRadians(cannonballAngle)));

        // Get the initial position of the cannonball
        double[] initial_position = OperateCannons.GetSelectedBarrelPosition();
        xPosition = (float)initial_position[0];
        yPosition = (float)initial_position[1];

        // Use the angle and barrel length to update the intiial position of the cannonball
        float dx = (float)(OperateCannons.barrelLength * System.Math.Cos(ToRadians(cannonballAngle))); // Change in x
        float dy = (float)(OperateCannons.barrelLength * System.Math.Sin(ToRadians(cannonballAngle))); // Change in y

        xPosition += dx;
        yPosition += dy;

        // Set the cannonball to its initial position
        transform.position = new Vector3((float)xPosition, (float)yPosition, 0);
    }
 // Destroys the cannonball and lets the OperateCannon class know
 private void DestroyCannonball()
 {
     Destroy(gameObject);
     OperateCannons.CleanActiveCannonballsList(); // Cleans the list of active cannonballs in the OperateCannons class
 }