/// <summary> /// Align to water normal. One normal by default, but can use a separate normal based on boat length vs width. This gives /// varying rotations based on boat dimensions. /// </summary> void FixedUpdateOrientation(ICollProvider collProvider, Vector3 undisplacedPos) { Vector3 normal, normalLongitudinal = Vector3.up; if (!collProvider.SampleNormal(ref undisplacedPos, _samplingData, out normal)) { normal = Vector3.up; } if (_useBoatLength) { // Compute a new sampling data that takes into account the boat length (as opposed to boat width) var thisRect = new Rect(transform.position.x, transform.position.z, 0f, 0f); collProvider.GetSamplingData(ref thisRect, _boatLength, _samplingDataLengthWise); if (collProvider.SampleNormal(ref undisplacedPos, _samplingDataLengthWise, out normalLongitudinal)) { var F = transform.forward; F.y = 0f; F.Normalize(); normal -= Vector3.Dot(F, normal) * F; var R = transform.right; R.y = 0f; R.Normalize(); normalLongitudinal -= Vector3.Dot(R, normalLongitudinal) * R; } collProvider.ReturnSamplingData(_samplingDataLengthWise); } if (_debugDraw) { Debug.DrawLine(transform.position, transform.position + 5f * normal, Color.green); } if (_debugDraw && _useBoatLength) { Debug.DrawLine(transform.position, transform.position + 5f * normalLongitudinal, Color.green); } var torqueWidth = Vector3.Cross(transform.up, normal); _rb.AddTorque(torqueWidth * _boyancyTorque, ForceMode.Acceleration); if (_useBoatLength) { var torqueLength = Vector3.Cross(transform.up, normalLongitudinal); _rb.AddTorque(torqueLength * _boyancyTorque, ForceMode.Acceleration); } }
public void ReturnSamplingData(SamplingData i_data) { _collProvider.ReturnSamplingData(i_data); }