コード例 #1
0
        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
        void FixedUpdateDrag(ICollProvider collProvider, Vector3 waterSurfaceVel)
        {
            // Apply drag relative to water
            var     pos = RB.position;
            Vector3 undispPos;

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

            var _velocityRelativeToWater = RB.velocity - waterSurfaceVel;

            var forcePosition = RB.position + _forceHeightOffset * Vector3.up;

            RB.AddForceAtPosition(Vector3.up * Vector3.Dot(Vector3.up, -_velocityRelativeToWater) * _dragInWaterUp, forcePosition, ForceMode.Acceleration);
            RB.AddForceAtPosition(transform.right * Vector3.Dot(transform.right, -_velocityRelativeToWater) * _dragInWaterRight, forcePosition, ForceMode.Acceleration);
            RB.AddForceAtPosition(transform.forward * Vector3.Dot(transform.forward, -_velocityRelativeToWater) * _dragInWaterForward, forcePosition, ForceMode.Acceleration);
        }
コード例 #3
0
 public bool ComputeUndisplacedPosition(ref Vector3 i_worldPos, SamplingData i_samplingData, out Vector3 undisplacedWorldPos)
 {
     return(_collProvider.ComputeUndisplacedPosition(ref i_worldPos, i_samplingData, out undisplacedWorldPos));
 }
コード例 #4
0
 public bool ComputeUndisplacedPosition(ref Vector3 in__worldPos, out Vector3 undisplacedWorldPos)
 {
     return(_collProvider.ComputeUndisplacedPosition(ref in__worldPos, out undisplacedWorldPos));
 }
コード例 #5
0
 public bool ComputeUndisplacedPosition(ref Vector3 i_worldPos, out Vector3 undisplacedWorldPos, float minSpatialLength)
 {
     return(_collProvider.ComputeUndisplacedPosition(ref i_worldPos, out undisplacedWorldPos, minSpatialLength));
 }
コード例 #6
0
 public bool ComputeUndisplacedPosition(ref Vector3 worldPos, ref Vector3 undisplacedWorldPos)
 {
     return(_collProvider.ComputeUndisplacedPosition(ref worldPos, ref undisplacedWorldPos));
 }