提交线修改

This commit is contained in:
Bob.Song
2026-04-16 16:54:49 +08:00
parent f2803c9d74
commit e8b1a3e0f1
3 changed files with 264 additions and 719 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -296,6 +296,7 @@ namespace NBF
ropeObject.transform.SetParent(_ropeRoot);
var rope = ropeObject.AddComponent<Rope>();
node.Rope = rope;
// rope.groundMask = LayerMask.GetMask("Terrain");
rope.startAnchor = node.Joint.connectedBody;
rope.endAnchor = node.body;
}

View File

@@ -60,7 +60,7 @@ public class Rope : MonoBehaviour
[Header("Simple Ground/Water Constraint (Cheap)")] [SerializeField]
private bool constrainToGround = false;
[SerializeField] private LayerMask groundMask = ~0;
[SerializeField] private LayerMask groundMask = 0;
[SerializeField, Min(0f)] private float groundRadius = 0.01f;
[SerializeField, Min(0f)] private float groundCastHeight = 1.0f;
[SerializeField, Min(0.01f)] private float groundCastDistance = 2.5f;
@@ -178,7 +178,7 @@ public class Rope : MonoBehaviour
private bool _isCulledByVisibility;
private int _tIdleSubdiv = -1;
private int _tMovingSubdiv = -1;
// Catmull t caches只缓存 idle/moving 两档,减少每帧重复乘法)
private struct TCaches
@@ -204,6 +204,7 @@ public class Rope : MonoBehaviour
RefreshVisibilityState(true);
}
private void OnValidate()
{
renderSubdivisionsIdle = Mathf.Max(renderSubdivisionsIdle, 1);
@@ -243,7 +244,7 @@ public class Rope : MonoBehaviour
_startTr = startAnchor ? startAnchor.transform : null;
_endTr = endAnchor ? endAnchor.transform : null;
}
private Transform GetActiveCameraTransform()
{
@@ -583,9 +584,10 @@ public class Rope : MonoBehaviour
Time.fixedDeltaTime
);
// 长度变化时额外压一点速度,减少收放线时抖动
float delta = Mathf.Abs(_targetLength - _currentLength);
if (delta > 0.0001f && lengthChangeVelocityKill > 0f)
// 仅在收线(目标长度小于当前长度)时额外压速度;
// 放线时不要压速度,否则新增节点下落会出现“顿一下再突然加速”。
float reelInDelta = _currentLength - _targetLength;
if (reelInDelta > 0.0001f && lengthChangeVelocityKill > 0f)
{
float keep = 1f - Mathf.Clamp01(lengthChangeVelocityKill);
for (int i = 1; i < _physicsNodes - 1; i++)
@@ -750,7 +752,8 @@ public class Rope : MonoBehaviour
SolveDistanceConstraintsSweep_Fast(last - 1, -1, -1, last, sweepStiffness);
}
private void SolveDistanceConstraintsSweep_Fast(int start, int endExclusive, int step, int last, float sweepStiffness)
private void SolveDistanceConstraintsSweep_Fast(int start, int endExclusive, int step, int last,
float sweepStiffness)
{
for (int i = start; i != endExclusive; i += step)
{
@@ -1091,4 +1094,4 @@ public class Rope : MonoBehaviour
for (int i = 0; i < _physicsNodes; i++)
Gizmos.DrawSphere(_pCurr[i], 0.01f);
}
}
}