提交测试脚本
This commit is contained in:
@@ -152,14 +152,14 @@ namespace NBF
|
||||
|
||||
_RigidBody.AddForce(buoyancy, ForceMode.Acceleration);
|
||||
|
||||
// // 在水面上滑行的近似流体动力学
|
||||
// if (_AccelerateDownhill > 0f)
|
||||
// {
|
||||
// _RigidBody.AddForce(_AccelerateDownhill * -Physics.gravity.y * new Vector3(normal.x, 0f, normal.z),
|
||||
// ForceMode.Acceleration);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// 在水面上滑行的近似流体动力学
|
||||
if (_AccelerateDownhill > 0f)
|
||||
{
|
||||
_RigidBody.AddForce(_AccelerateDownhill * -Physics.gravity.y * new Vector3(normal.x, 0f, normal.z),
|
||||
ForceMode.Acceleration);
|
||||
}
|
||||
|
||||
|
||||
// // 朝向
|
||||
// // 与水面垂直。默认使用一个垂直方向,但也可以使用单独的垂直方向。
|
||||
// // 根据船的长度与宽度的比例。这会根据船只的不同而产生不同的旋转效果。
|
||||
@@ -174,8 +174,30 @@ namespace NBF
|
||||
// _RigidBody.AddTorque(torqueWidth * _BuoyancyTorqueStrength, ForceMode.Acceleration);
|
||||
// _RigidBody.AddTorque(-_AngularDrag * _RigidBody.angularVelocity);
|
||||
// }
|
||||
//
|
||||
//
|
||||
|
||||
// 朝向(改进的扭矩版本)
|
||||
{
|
||||
var normalLatitudinal = normal;
|
||||
|
||||
if (_Debug._DrawQueries)
|
||||
Debug.DrawLine(transform.position, transform.position + 5f * normalLatitudinal, Color.green);
|
||||
|
||||
// 限制扭矩强度基于物体质量
|
||||
var massFactor = Mathf.Clamp(_RigidBody.mass / 0.1f, 0.1f, 1f); // 质量越小,扭矩越弱
|
||||
var adjustedTorqueStrength = _BuoyancyTorqueStrength * massFactor;
|
||||
|
||||
var torqueWidth = Vector3.Cross(transform.up, normalLatitudinal);
|
||||
|
||||
// 添加最大扭矩限制
|
||||
var maxTorque = 5f; // 根据需要调整
|
||||
var finalTorque = Vector3.ClampMagnitude(torqueWidth * adjustedTorqueStrength, maxTorque);
|
||||
|
||||
_RigidBody.AddTorque(finalTorque, ForceMode.Acceleration);
|
||||
_RigidBody.AddTorque(-_AngularDrag * _RigidBody.angularVelocity, ForceMode.Acceleration);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 相对于水进行拖拽操作
|
||||
if (_Drag != Vector3.zero)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user