diff --git a/Assets/ResRaw/Maps/Map1/Map1.unity b/Assets/ResRaw/Maps/Map1/Map1.unity index f19821348..3e9a1aee3 100644 --- a/Assets/ResRaw/Maps/Map1/Map1.unity +++ b/Assets/ResRaw/Maps/Map1/Map1.unity @@ -26,7 +26,7 @@ RenderSettings: m_AmbientIntensity: 0.8050667 m_AmbientMode: 0 m_SubtractiveShadowColor: {r: 0.8679245, g: 0.8679245, b: 0.8679245, a: 1} - m_SkyboxMaterial: {fileID: 16041075} + m_SkyboxMaterial: {fileID: 1948842527} m_HaloStrength: 0.5 m_FlareStrength: 1 m_FlareFadeSpeed: 3 @@ -119,54 +119,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!21 &16041075 -Material: - serializedVersion: 8 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: Enviro/Skybox - m_Shader: {fileID: 4800000, guid: 34fee0a1b19b20b45aea7483b5f757da, type: 3} - m_Parent: {fileID: 0} - m_ModifiedSerializedProperties: 0 - m_ValidKeywords: [] - m_InvalidKeywords: [] - m_LightmapFlags: 4 - m_EnableInstancingVariants: 0 - m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} - disabledShaderPasses: [] - m_LockedProperties: - m_SavedProperties: - serializedVersion: 3 - m_TexEnvs: - - _GalaxyTex: - m_Texture: {fileID: 8900000, guid: 5734983fc81450b4187c3cfa5985edef, type: 3} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _MoonGlowTex: - m_Texture: {fileID: 2800000, guid: 6838e0810da4e49488b5d9a6ee76eb07, type: 3} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _MoonTex: - m_Texture: {fileID: 2800000, guid: c6fd9f694390e0245b6dca5812065950, type: 3} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _StarsTex: - m_Texture: {fileID: 8900000, guid: b5a7175da0f133b4d951c19c9c2cebfc, type: 3} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - - _SunTex: - m_Texture: {fileID: 2800000, guid: c95bed5306e94f24ba5802d841607ac7, type: 3} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - m_Ints: [] - m_Floats: [] - m_Colors: [] - m_BuildTextureStacks: [] - m_AllowLocking: 1 --- !u!1 &116710580 GameObject: m_ObjectHideFlags: 0 @@ -1488,6 +1440,54 @@ MonoBehaviour: _MaximumSpeed: 100 _WarnOnSpeedClamp: 0 _DebugSubsteps: 0 +--- !u!21 &1948842527 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Enviro/Skybox + m_Shader: {fileID: 4800000, guid: 34fee0a1b19b20b45aea7483b5f757da, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _GalaxyTex: + m_Texture: {fileID: 8900000, guid: 5734983fc81450b4187c3cfa5985edef, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MoonGlowTex: + m_Texture: {fileID: 2800000, guid: 6838e0810da4e49488b5d9a6ee76eb07, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MoonTex: + m_Texture: {fileID: 2800000, guid: c6fd9f694390e0245b6dca5812065950, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _StarsTex: + m_Texture: {fileID: 8900000, guid: b5a7175da0f133b4d951c19c9c2cebfc, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SunTex: + m_Texture: {fileID: 2800000, guid: c95bed5306e94f24ba5802d841607ac7, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: [] + m_Colors: [] + m_BuildTextureStacks: [] + m_AllowLocking: 1 --- !u!1 &2034802495 GameObject: m_ObjectHideFlags: 0 @@ -8268,7 +8268,7 @@ MonoBehaviour: WaterObject: {fileID: 718680767} Node: {fileID: 3673832994973231279} GearNode: {fileID: 6022323663597824692} - Water: {fileID: 0} + Water: {fileID: 718680768} LineRenderer: {fileID: 0} FPS: 0 updateInterval: 0.2 diff --git a/Assets/ResRaw/Prefabs/Line/fishing line float set.prefab b/Assets/ResRaw/Prefabs/Line/fishing line float set.prefab index 967536959..a902fa32b 100644 --- a/Assets/ResRaw/Prefabs/Line/fishing line float set.prefab +++ b/Assets/ResRaw/Prefabs/Line/fishing line float set.prefab @@ -454,7 +454,7 @@ GameObject: - component: {fileID: 54298866000586118} - component: {fileID: 153691655494134957} - component: {fileID: 2717383850592950062} - - component: {fileID: 3104700584461846010} + - component: {fileID: 8545743762334745476} m_Layer: 16 m_Name: Float m_TagString: Untagged @@ -620,29 +620,56 @@ MonoBehaviour: m_EditorClassIdentifier: Assembly-CSharp::NBF.BobberController _rbody: {fileID: 54298866000586118} joint: {fileID: 153691655494134957} - _buoyancy: {fileID: 3104700584461846010} ---- !u!114 &3104700584461846010 +--- !u!114 &8545743762334745476 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1858052053854210} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: dd1aa9f0de8b435448c6893ecc60d021, type: 3} + m_Script: {fileID: 11500000, guid: f91c9d873c83492ca6d5e3e3a67c1760, type: 3} m_Name: - m_EditorClassIdentifier: Assembly-CSharp::Buoyancy - includeDeformation: 1 - sphereRadiusApproximation: 0.1 - waveForceMultiplier: 0.01 - currentSpeedMultiplier: 0.01 - dragMultiplier: 1 - defaultRigidbodyDrag: 5 - underwaterRigidbodyAngularDrag: 5 - overwaterRigidbodyAngularDrag: 1 - surfaceTensionDamping: 10 - applyForceWithRandomOffset: 0 + m_EditorClassIdentifier: Assembly-CSharp::CapsuleBuoyancyStable + buoyancyScale: 1.6 + samplePoints: 9 + submergenceCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 1 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1 + value: 1 + inSlope: 1 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + verticalDamping: 0.6 + angularDamping: 0.1 + uprightSpring: 0 + uprightDamping: 0.5 + uprightAxis: 1 + extraDragInWater: 0.8 + extraAngularDragInWater: 0.3 + nearUprightDampingReduce: 0.6 + nearUprightAngleDeg: 12 + _waterRenderer: {fileID: 0} + _Layer: 1 + _ObjectWidth: 3 drawDebug: 1 --- !u!1 &1933124697579601 GameObject: diff --git a/Assets/ResRaw/gfx/bobbers/expressfishing/bob_25004/bob_25004.prefab b/Assets/ResRaw/gfx/bobbers/expressfishing/bob_25004/bob_25004.prefab index b73cced78..d566b7bfc 100644 --- a/Assets/ResRaw/gfx/bobbers/expressfishing/bob_25004/bob_25004.prefab +++ b/Assets/ResRaw/gfx/bobbers/expressfishing/bob_25004/bob_25004.prefab @@ -70,10 +70,10 @@ CapsuleCollider: m_ProvidesContacts: 0 m_Enabled: 1 serializedVersion: 2 - m_Radius: 0.002 - m_Height: 0.03 + m_Radius: 0.003 + m_Height: 0.02 m_Direction: 1 - m_Center: {x: 0, y: 0.01, z: 0} + m_Center: {x: 0, y: 0.03, z: 0} --- !u!1 &1236424003946422 GameObject: m_ObjectHideFlags: 0 @@ -367,7 +367,7 @@ Transform: m_GameObject: {fileID: 1696436611728297872} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: -0.04, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: diff --git a/Assets/Scenes/BobberTest.unity b/Assets/Scenes/BobberTest.unity index 0be26d0e5..6da8b6213 100644 --- a/Assets/Scenes/BobberTest.unity +++ b/Assets/Scenes/BobberTest.unity @@ -1177,6 +1177,7 @@ MonoBehaviour: topConnector: {fileID: 209664165} bottomConnector: {fileID: 332592725} waterline: {fileID: 223862664} + collider: {fileID: 0} --- !u!1 &920563739 GameObject: m_ObjectHideFlags: 0 @@ -2519,6 +2520,7 @@ MonoBehaviour: topConnector: {fileID: 1549463780} bottomConnector: {fileID: 726690746} waterline: {fileID: 1627634078} + collider: {fileID: 0} --- !u!1 &1690494754 GameObject: m_ObjectHideFlags: 0 @@ -2641,6 +2643,7 @@ MonoBehaviour: topConnector: {fileID: 1224158073} bottomConnector: {fileID: 1336541387} waterline: {fileID: 666518409} + collider: {fileID: 0} --- !u!4 &1866024594 stripped Transform: m_CorrespondingSourceObject: {fileID: 8356280719142672529, guid: 84f17dfc7c7a7485296643a4e64d6200, type: 3} @@ -2999,6 +3002,7 @@ MonoBehaviour: topConnector: {fileID: 1828830192} bottomConnector: {fileID: 1690494755} waterline: {fileID: 623951639} + collider: {fileID: 0} --- !u!1 &1586000250375033 GameObject: m_ObjectHideFlags: 0 @@ -3041,6 +3045,7 @@ GameObject: m_Component: - component: {fileID: 4046714554611455} - component: {fileID: 309487077947173374} + - component: {fileID: 309487077947173375} m_Layer: 0 m_Name: bob_25002 m_TagString: Untagged @@ -3394,6 +3399,30 @@ MonoBehaviour: topConnector: {fileID: 4466248854207531} bottomConnector: {fileID: 4064788320456926} waterline: {fileID: 4902566405131541} + collider: {fileID: 309487077947173375} +--- !u!136 &309487077947173375 +CapsuleCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1818733047993069} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Radius: 0.004 + m_Height: 0.025 + m_Direction: 1 + m_Center: {x: 0, y: 0.04, z: 0} --- !u!4 &389927712696538647 Transform: m_ObjectHideFlags: 0 @@ -4665,6 +4694,7 @@ MonoBehaviour: topConnector: {fileID: 1159196036679945669} bottomConnector: {fileID: 4333116976202729697} waterline: {fileID: 7961972470609608556} + collider: {fileID: 0} --- !u!1 &3062767698477047043 GameObject: m_ObjectHideFlags: 0 @@ -5081,6 +5111,7 @@ MonoBehaviour: topConnector: {fileID: 3065647928701135441} bottomConnector: {fileID: 3065526845897688740} waterline: {fileID: 3068616352015752047} + collider: {fileID: 0} --- !u!54 &3372919389234347911 Rigidbody: m_ObjectHideFlags: 0 @@ -5606,6 +5637,7 @@ MonoBehaviour: topConnector: {fileID: 9066712976035742038} bottomConnector: {fileID: 5901816832231670898} waterline: {fileID: 269017554130809855} + collider: {fileID: 0} --- !u!136 &4959874663812492083 CapsuleCollider: m_ObjectHideFlags: 0 @@ -6507,6 +6539,8 @@ MonoBehaviour: uprightAxis: 1 extraDragInWater: 0.8 extraAngularDragInWater: 0.8 + nearUprightDampingReduce: 0.6 + nearUprightAngleDeg: 12 _waterRenderer: {fileID: 2531380344179187550} _Layer: 1 _ObjectWidth: 3 @@ -6738,7 +6772,6 @@ GameObject: m_Component: - component: {fileID: 8107394097429219735} - component: {fileID: 8094040829892155629} - - component: {fileID: 8264424693587136968} - component: {fileID: 8264424693587136966} - component: {fileID: 6135364979465448005} - component: {fileID: 8264424693587136969} @@ -6748,7 +6781,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!1 &8112602444043959218 GameObject: m_ObjectHideFlags: 0 @@ -7252,29 +7285,6 @@ ConfigurableJoint: m_EnablePreprocessing: 0 m_MassScale: 1 m_ConnectedMassScale: 1 ---- !u!136 &8264424693587136968 -CapsuleCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8112599368562234729} - m_Material: {fileID: 0} - m_IncludeLayers: - serializedVersion: 2 - m_Bits: 0 - m_ExcludeLayers: - serializedVersion: 2 - m_Bits: 0 - m_LayerOverridePriority: 0 - m_IsTrigger: 0 - m_ProvidesContacts: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Radius: 0.004 - m_Height: 0.025 - m_Direction: 1 - m_Center: {x: 0, y: 0.04, z: 0} --- !u!114 &8264424693587136969 MonoBehaviour: m_ObjectHideFlags: 0 @@ -7319,7 +7329,9 @@ MonoBehaviour: uprightDamping: 0.5 uprightAxis: 1 extraDragInWater: 0.8 - extraAngularDragInWater: 0.8 + extraAngularDragInWater: 0.3 + nearUprightDampingReduce: 0.6 + nearUprightAngleDeg: 12 _waterRenderer: {fileID: 2531380344179187550} _Layer: 1 _ObjectWidth: 3 diff --git a/Assets/Scripts/Common/Assets/BobberAsset.cs b/Assets/Scripts/Common/Assets/BobberAsset.cs index c05313535..f48dec233 100644 --- a/Assets/Scripts/Common/Assets/BobberAsset.cs +++ b/Assets/Scripts/Common/Assets/BobberAsset.cs @@ -24,5 +24,6 @@ namespace NBF /// 水线 /// public Transform waterline; + } } \ No newline at end of file diff --git a/Assets/Scripts/Fishing/Tackle/FBobber.cs b/Assets/Scripts/Fishing/Tackle/FBobber.cs index 9aad4e2dc..ae4d9d3af 100644 --- a/Assets/Scripts/Fishing/Tackle/FBobber.cs +++ b/Assets/Scripts/Fishing/Tackle/FBobber.cs @@ -9,6 +9,8 @@ namespace NBF // transform.position = Rod.lineHandler.LineConnector_1.transform.position; SetParent(Rod.Line.Bobber.transform); transform.localPosition = Vector3.zero; + var buoyancy = GetComponentInParent(); + buoyancy.InitBobber(); } } } \ No newline at end of file diff --git a/Assets/Scripts/Test/CapsuleBuoyancyStable.cs b/Assets/Scripts/Test/CapsuleBuoyancyStable.cs index b20789531..a98bffcf8 100644 --- a/Assets/Scripts/Test/CapsuleBuoyancyStable.cs +++ b/Assets/Scripts/Test/CapsuleBuoyancyStable.cs @@ -4,7 +4,7 @@ using UnityEngine; using WaveHarmonic.Crest; [DisallowMultipleComponent] -[RequireComponent(typeof(Rigidbody), typeof(CapsuleCollider))] +[RequireComponent(typeof(Rigidbody))] public class CapsuleBuoyancyStable : MonoBehaviour { [Header("Buoyancy")] [Tooltip("完全浸没时总浮力 = mass*g*buoyancyScale。>1 更浮。")] @@ -15,8 +15,8 @@ public class CapsuleBuoyancyStable : MonoBehaviour [Tooltip("浸没比例曲线(0=刚碰水, 1=充分在水下)。")] public AnimationCurve submergenceCurve = AnimationCurve.Linear(0, 0, 1, 1); - [Header("Damping")] [Tooltip("上浮方向速度阻尼(越大越不弹)。")] - public float verticalDamping = 3.0f; + [Header("Damping")] [Tooltip("上浮方向速度阻尼(越大越不弹)。本版本:只在“浮力中心”施加一次,不再在每个采样点施加,避免90°附近转不动。")] + public float verticalDamping = 0.6f; [Tooltip("整体角速度阻尼(只施加一次,不要太大)。")] public float angularDamping = 0.6f; @@ -31,8 +31,15 @@ public class CapsuleBuoyancyStable : MonoBehaviour [Header("Water Drag")] public float extraDragInWater = 0.8f; public float extraAngularDragInWater = 0.8f; - #region Crest5相关信息 + [Header("Anti-stiction near upright")] + [Tooltip("在接近竖直(例如90->80度附近)时,降低vertical damping,避免“粘住”。0=关闭。")] + [Range(0f, 1f)] + public float nearUprightDampingReduce = 0.6f; + [Tooltip("接近竖直的判定角度(度)。例如 12 表示在 |angle| < 12° 附近逐步降低阻尼。")] [Range(1f, 30f)] + public float nearUprightAngleDeg = 12f; + + #region Crest5相关信息 public WaterRenderer _waterRenderer; @@ -44,11 +51,7 @@ public class CapsuleBuoyancyStable : MonoBehaviour readonly SampleFlowHelper _SampleFlowHelper = new(); - /// - /// 查询水面信息点位 - /// Vector3[] _QueryPoints; - Vector3[] _QueryResultDisplacements; Vector3[] _QueryResultVelocities; Vector3[] _QueryResultNormal; @@ -61,106 +64,147 @@ public class CapsuleBuoyancyStable : MonoBehaviour CapsuleCollider _cap; float _baseDrag, _baseAngularDrag; + [SerializeField] private bool _init = false; + void Awake() { _rb = GetComponent(); - _cap = GetComponent(); _baseDrag = _rb.linearDamping; _baseAngularDrag = _rb.angularDamping; } - private void Start() + void Start() { int length = Mathf.Max(3, samplePoints); _QueryPoints = new Vector3[length]; _QueryResultDisplacements = new Vector3[length]; _QueryResultVelocities = new Vector3[length]; _QueryResultNormal = new Vector3[length]; + + } + + public void InitBobber() + { + if (_waterRenderer == null && SceneSettings.Instance) + { + _waterRenderer = SceneSettings.Instance.Water; + } + _cap = GetComponentInChildren(); + _init = true; } void FixedUpdate() { - if (!_waterRenderer) - { - return; - } + if (!_init) return; + if (!_waterRenderer) return; + GetWorldCapsule(out Vector3 a, out Vector3 b, out float radius); int n = Mathf.Max(3, samplePoints); + if (_QueryPoints == null || _QueryPoints.Length != n) + { + _QueryPoints = new Vector3[n]; + _QueryResultDisplacements = new Vector3[n]; + _QueryResultVelocities = new Vector3[n]; + _QueryResultNormal = new Vector3[n]; + } + float fullBuoyancy = _rb.mass * Physics.gravity.magnitude * buoyancyScale; float perPointMax = fullBuoyancy / n; - float subSum = 0f; - int wetCount = 0; - - for (int i = 0; i < _QueryPoints.Length; i++) + // 采样点 + for (int i = 0; i < n; i++) { float t = (float)i / (n - 1); - Vector3 p = Vector3.Lerp(a, b, t); - _QueryPoints[i] = p; + _QueryPoints[i] = Vector3.Lerp(a, b, t); } - - // 查询 + // Crest 查询 var collisions = _waterRenderer.AnimatedWavesLod.Provider; collisions.Query(GetHashCode(), _ObjectWidth, _QueryPoints, _QueryResultDisplacements, _QueryResultNormal, _QueryResultVelocities, _Layer); + float subSum = 0f; + int wetCount = 0; + // 用于计算“浮力中心”(Center of Buoyancy)与水流速度平均 + Vector3 cobSum = Vector3.zero; + Vector3 wvSum = Vector3.zero; + float cobW = 0f; + + // 1) 多点只加浮力(不再在每点加vertical damping) for (int i = 0; i < n; i++) { - float t = (float)i / (n - 1); - Vector3 p = Vector3.Lerp(a, b, t); + Vector3 p = _QueryPoints[i]; - float waterH = - _QueryResultDisplacements[i].y + _waterRenderer.SeaLevel; //GaiaConstants.Water.GetWaterHeight(p); - float depth = waterH - p.y; // >0 在水下 + float waterH = _QueryResultDisplacements[i].y + _waterRenderer.SeaLevel; + float depth = waterH - p.y; - float sub = Mathf.InverseLerp(-radius, radius, depth); // 0..1 + float sub = Mathf.InverseLerp(-radius, radius, depth); if (sub <= 0f) continue; sub = Mathf.Clamp01(submergenceCurve.Evaluate(sub)); + subSum += sub; wetCount++; - Vector3 buoyDir = Vector3.up; + cobSum += p * sub; + wvSum += _QueryResultVelocities[i] * sub; + cobW += sub; - // Vector3 waterVel = GaiaConstants.Water.GetWaterVelocity(p); - Vector3 waterVel = _QueryResultVelocities[i]; - Vector3 pointVel = _rb.GetPointVelocity(p); - Vector3 relVel = pointVel - waterVel; - - // 浮力 - Vector3 buoyForce = buoyDir * (perPointMax * sub); - - // 只阻尼上浮方向速度分量(防弹跳) - float vUp = Vector3.Dot(relVel, buoyDir); - Vector3 dampForce = -buoyDir * (vUp * verticalDamping * _rb.mass * sub); - - _rb.AddForceAtPosition(buoyForce + dampForce, p, ForceMode.Force); + Vector3 buoyForce = Vector3.up * (perPointMax * sub); + _rb.AddForceAtPosition(buoyForce, p, ForceMode.Force); if (drawDebug) { Debug.DrawLine(p, p + buoyForce / (_rb.mass * 10f), Color.cyan, 0f, false); - Debug.DrawLine(p, p + dampForce / (_rb.mass * 10f), Color.yellow, 0f, false); } } float subAvg = (wetCount > 0) ? (subSum / wetCount) : 0f; - // 角阻尼:只加一次(关键修复点) + // 2) vertical damping:只在“浮力中心”施加一次(关键修复:不再产生抑制旋转的力矩) + if (subAvg > 0f && cobW > 1e-6f) + { + Vector3 cob = cobSum / cobW; + Vector3 waterVelAvg = wvSum / cobW; + + // 接近竖直时降低vertical damping,避免90->80度“粘住” + float vdScale = 1f; + if (nearUprightDampingReduce > 0f) + { + Vector3 axisWorld = GetAxisWorld(uprightAxis); + float angleFromUp = Vector3.Angle(axisWorld, Vector3.up); // 0=竖直 + float t = Mathf.Clamp01(angleFromUp / Mathf.Max(0.001f, nearUprightAngleDeg)); + // t=0(很竖直) -> 1(离开竖直) + vdScale = Mathf.Lerp(1f - nearUprightDampingReduce, 1f, t); + } + + Vector3 pointVel = _rb.GetPointVelocity(cob); + Vector3 relVel = pointVel - waterVelAvg; + float vUp = Vector3.Dot(relVel, Vector3.up); + + Vector3 dampForce = -Vector3.up * (vUp * verticalDamping * _rb.mass * subAvg * vdScale); + _rb.AddForceAtPosition(dampForce, cob, ForceMode.Force); + + if (drawDebug) + { + Debug.DrawLine(cob, cob + dampForce / (_rb.mass * 10f), Color.yellow, 0f, false); + } + } + + // 3) 角阻尼:只加一次 if (subAvg > 0f) { _rb.AddTorque(-_rb.angularVelocity * (angularDamping * _rb.mass * subAvg), ForceMode.Force); } - // 可选:upright 稳定器(更像“浮漂自动立起来”) + // 4) upright(保持你原逻辑) if (subAvg > 0f && uprightSpring > 0f) { Vector3 axisWorld = GetAxisWorld(uprightAxis); Vector3 targetUp = Vector3.up; - // 误差轴:axisWorld 需要对齐 targetUp(也可反过来按你浮漂模型选) Vector3 errorAxis = Vector3.Cross(axisWorld, targetUp); float errorMag = errorAxis.magnitude; @@ -168,7 +212,6 @@ public class CapsuleBuoyancyStable : MonoBehaviour { errorAxis /= errorMag; - // “弹簧”力矩 + 阻尼(防止在两个角度间抽动) Vector3 springTorque = errorAxis * (uprightSpring * errorMag * _rb.mass); Vector3 dampTorque = -_rb.angularVelocity * (uprightDamping * _rb.mass); @@ -176,7 +219,7 @@ public class CapsuleBuoyancyStable : MonoBehaviour } } - // 入水整体 drag + // 5) 入水 drag if (subAvg > 0.001f) { _rb.linearDamping = _baseDrag + extraDragInWater * subAvg; @@ -202,7 +245,7 @@ public class CapsuleBuoyancyStable : MonoBehaviour void GetWorldCapsule(out Vector3 a, out Vector3 b, out float radius) { Vector3 lossy = transform.lossyScale; - int dir = _cap.direction; // 0=X,1=Y,2=Z + int dir = _cap.direction; float scaleAlong = (dir == 0) ? Mathf.Abs(lossy.x) : (dir == 1) ? Mathf.Abs(lossy.y) : Mathf.Abs(lossy.z); @@ -224,16 +267,14 @@ public class CapsuleBuoyancyStable : MonoBehaviour b = center + half; } - - private void OnDrawGizmosSelected() + void OnDrawGizmosSelected() { - if (drawDebug) - { - // 绘制 Rigidbody 的重心点位 - Vector3 centerOfMassWorld = transform.TransformPoint(_rb != null ? _rb.centerOfMass : Vector3.zero); - Gizmos.color = Color.cyan; - Gizmos.DrawSphere(centerOfMassWorld, 0.1f); - Gizmos.DrawLine(centerOfMassWorld, centerOfMassWorld + Vector3.up * 0.5f); - } + if (!drawDebug) return; + + if (_rb == null) _rb = GetComponent(); + Vector3 centerOfMassWorld = transform.TransformPoint(_rb != null ? _rb.centerOfMass : Vector3.zero); + Gizmos.color = Color.cyan; + Gizmos.DrawSphere(centerOfMassWorld, 0.1f); + Gizmos.DrawLine(centerOfMassWorld, centerOfMassWorld + Vector3.up * 0.5f); } } \ No newline at end of file diff --git a/Packages/com.waveharmonic.crest/Runtime/Materials/Water Volume.mat b/Packages/com.waveharmonic.crest/Runtime/Materials/Water Volume.mat index 0a459305e..157ea619a 100644 --- a/Packages/com.waveharmonic.crest/Runtime/Materials/Water Volume.mat +++ b/Packages/com.waveharmonic.crest/Runtime/Materials/Water Volume.mat @@ -12,7 +12,6 @@ Material: m_Parent: {fileID: 0} m_ModifiedSerializedProperties: 0 m_ValidKeywords: - - _CREST_FLOW_LOD - d_Crest_NoMaskDepth - d_Dithering m_InvalidKeywords: @@ -22,16 +21,16 @@ Material: - _BUILTIN_ALPHATEST_ON - _BUILTIN_AlphaClip - _BUILTIN_SURFACE_TYPE_TRANSPARENT - - _BUILTIN_TRANSPARENT_RECEIVES_SHADOWS - _DOUBLESIDED_ON - _EMISSION - _ENABLE_FOG_ON_TRANSPARENT + - _REFRACTION_PLANE - _SURFACE_TYPE_TRANSPARENT - _TRANSPARENT_WRITES_MOTION_VEC - m_LightmapFlags: 4 + m_LightmapFlags: 2 m_EnableInstancingVariants: 0 - m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 + m_DoubleSidedGI: 1 + m_CustomRenderQueue: 3000 stringTagMap: {} disabledShaderPasses: [] m_LockedProperties: @@ -52,7 +51,7 @@ Material: - _Crest_Version: 0 m_Floats: - CREST_FLOW: 0 - - _CREST_FLOW_LOD: 1 + - _CREST_FLOW_LOD: 0 - _Crest_AmbientTerm: 1 - _Crest_Anisotropy: 0.5 - _Crest_CausticsDepthOfField: 6 diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index 0a7faed54..19bbbb307 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -9,34 +9,34 @@ EditorUserSettings: value: 18134705175a055722080a3115371d4a0d55006876786860616b0471b8b07a68ffab74f9ee2a3a30300cea1a11320d0beb1a0c25f7060f494b4cc80018eb09361fc211cb1f862d19c51d19dcc413d6ade0d8ddfcddf9f4d9d29195fcfde6ebeae6f0a9c9afa6f8c5b89ff7a1aacececac4eba4d7c9d28bda flags: 0 RecentlyUsedSceneGuid-0: - value: 01085257040c5f0e0c0d5f27457b0f444e4e192c7b2d7e6428794d67e3b36668 - flags: 0 - RecentlyUsedSceneGuid-1: - value: 52530c5601535f020f565a2043770d1612154d2f747975692c7b4e66b5e3303b - flags: 0 - RecentlyUsedSceneGuid-2: value: 5302035e5c530f0b5c0c557416270d44134e4d28787c76332f7e1f6bb1b76169 flags: 0 - RecentlyUsedSceneGuid-3: + RecentlyUsedSceneGuid-1: value: 5050570401015d0a545d087047710e44154e1c2e7f787368782c4e60e1e1636b flags: 0 - RecentlyUsedSceneGuid-4: + RecentlyUsedSceneGuid-2: value: 520004535d5751085c595a7047730e4440161e7d787022342f2d486bb4b6626a flags: 0 - RecentlyUsedSceneGuid-5: + RecentlyUsedSceneGuid-3: value: 5a035755520650595b5b5f2345740e4447154a73742d70632b7d4b65e4e66d69 flags: 0 - RecentlyUsedSceneGuid-6: + RecentlyUsedSceneGuid-4: value: 0508070250545c58585e0924437b5d444f4e4b7f7d7a71627f794c64b2e5633a flags: 0 - RecentlyUsedSceneGuid-7: + RecentlyUsedSceneGuid-5: + value: 0054045155060d5a5c575f7045270d44474f4e7c7f7924637e2a1832b1b5636d + flags: 0 + RecentlyUsedSceneGuid-6: value: 5409030052070d0d095a5c7412745e444216417c2e7a23642b7e1832bab9363e flags: 0 - RecentlyUsedSceneGuid-8: + RecentlyUsedSceneGuid-7: value: 5606515f5605500b0e5c5c2615760a444615487c2a2a2467297d1932b7e4673a flags: 0 + RecentlyUsedSceneGuid-8: + value: 5309035757065a0a54575f7216265c4444151d28792e72627d2f1935bbb8673a + flags: 0 RecentlyUsedSceneGuid-9: - value: 0054045155060d5a5c575f7045270d44474f4e7c7f7924637e2a1832b1b5636d + value: 5505015f5c515a085f5b092149760f441716407a787d7564287b1b36e7e1366e flags: 0 UnityEditor.ShaderGraph.Blackboard: value: 18135939215a0a5004000b0e15254b524c030a3f2964643d120d1230e9e93a3fd6e826abbd2e2d293c4ead313b08042de6030a0afa240c0d020be94c4ba75e435d8715fa32c70d15d11612dacc11fee5d3c5d1fe9ab1bf968e93e2ffcbc3e7e2f0b3ffe0e8b0be9afeffa9ffff8e85dd8390e2969e8899daa7