void FixedUpdateBuoyancy(ICollProvider collProvider)
        {
            float archimedesForceMagnitude = WATER_DENSITY * Mathf.Abs(Physics.gravity.y);

            for (int i = 0; i < _forcePoints.Length; i++)
            {
                FloaterForcePoints point = _forcePoints[i];
                var transformedPoint     = transform.TransformPoint(point._offsetPosition + new Vector3(0, _centerOfMass.y, 0));

                Vector3 undispPos;
                if (!collProvider.ComputeUndisplacedPosition(ref transformedPoint, _samplingData, out undispPos))
                {
                    // If we couldn't get wave shape, assume flat water at sea level
                    undispPos   = transformedPoint;
                    undispPos.y = OceanRenderer.Instance.SeaLevel;
                }

                Vector3 displaced;
                collProvider.SampleDisplacement(ref undispPos, _samplingData, out displaced);

                var dispPos    = undispPos + displaced;
                var heightDiff = dispPos.y - transformedPoint.y;
                if (heightDiff > 0)
                {
                    RB.AddForceAtPosition(archimedesForceMagnitude * heightDiff * Vector3.up * point._weight * _forceMultiplier / _totalWeight, transformedPoint);
                }
            }
        }
示例#2
0
 public bool SampleDisplacement(ref Vector3 worldPos, ref Vector3 displacement)
 {
     return(_collProvider.SampleDisplacement(ref worldPos, ref displacement));
 }
 // displacement queries are not cached - only the height computations
 public bool SampleDisplacement(ref Vector3 in__worldPos, out Vector3 displacement)
 {
     return(_collProvider.SampleDisplacement(ref in__worldPos, out displacement));
 }
 public bool SampleDisplacement(ref Vector3 i_worldPos, SamplingData i_samplingData, out Vector3 o_displacement)
 {
     return(_collProvider.SampleDisplacement(ref i_worldPos, i_samplingData, out o_displacement));
 }
 public bool SampleDisplacement(ref Vector3 i_worldPos, out Vector3 o_displacement, float minSpatialLength)
 {
     return(_collProvider.SampleDisplacement(ref i_worldPos, out o_displacement, minSpatialLength));
 }