Esempio n. 1
0
        //Add all forces that act on the squares below the water
        void AddUnderWaterForces()
        {
            //Get all triangles
            List <triangleData> underWaterTriangleData = modifyBoatMesh.underWaterTriangleData;

            for (int i = 0; i < underWaterTriangleData.Count; i++)
            {
                //use only unerwater triangle
                triangleData triangleData = underWaterTriangleData[i];

                //Calculate the buoyancy force
                Vector3 buoyancyForce = BuoyancyForce(rhoWater, triangleData);
                //Add the force to the boat
                boatRB.AddForceAtPosition(buoyancyForce, triangleData.center);


                //Debug

                //Normal
                Debug.DrawRay(triangleData.center, triangleData.normal * 0.5f, Color.white);

                //Buoyancy
                Debug.DrawRay(triangleData.center, buoyancyForce.normalized * -0.2f, Color.blue);
            }
        }
Esempio n. 2
0
        //The buoyancy force so the boat can float
        private Vector3 BuoyancyForce(float rho, triangleData triangleData)
        {
            //Buoyancy is a hydrostatic force - it's there even if the water isn't flowing or if the boat stays still

            // F_buoyancy = rho * g * V
            // rho - density of the mediaum you are in
            // g - gravity
            // V - volume of fluid directly above the curved surface

            // V = z * S * n
            // z - distance to surface
            // S - surface area
            // n - normal to the surface
            Vector3 buoyancyForce = rho * Physics.gravity.y * triangleData.distanceToSurface * triangleData.area * triangleData.normal;

            //The vertical component of the hydrostatic forces don't cancel out but the horizontal do
            buoyancyForce.x = 0f;
            buoyancyForce.z = 0f;

            return(buoyancyForce);
        }