修改线逻辑
This commit is contained in:
@@ -59,6 +59,9 @@ MonoBehaviour:
|
||||
lengthChangeVelocityKill: 0.6
|
||||
minSlack: 0.002
|
||||
headMinLen: 0.01
|
||||
collisionMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
constrainToGround: 1
|
||||
groundMask:
|
||||
serializedVersion: 2
|
||||
@@ -672,6 +675,9 @@ MonoBehaviour:
|
||||
lengthChangeVelocityKill: 0.6
|
||||
minSlack: 0.002
|
||||
headMinLen: 0.01
|
||||
collisionMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
constrainToGround: 1
|
||||
groundMask:
|
||||
serializedVersion: 2
|
||||
|
||||
@@ -15,35 +15,6 @@ public class RopeFishLineEditor : Editor
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
if (GUILayout.Button("增加0.5长度"))
|
||||
{
|
||||
_target.AddTargetLength(0.5f);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("减小0.5长度"))
|
||||
{
|
||||
_target.AddTargetLength(-0.5f);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("增加0.1长度"))
|
||||
{
|
||||
_target.AddTargetLength(0.1f);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("减小0.1长度"))
|
||||
{
|
||||
_target.AddTargetLength(-0.1f);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("增加0.01长度"))
|
||||
{
|
||||
_target.AddTargetLength(0.01f);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("减小0.01长度"))
|
||||
{
|
||||
_target.AddTargetLength(-0.01f);
|
||||
}
|
||||
|
||||
|
||||
if (GUILayout.Button("打印总长度"))
|
||||
|
||||
@@ -41,6 +41,11 @@ public class Rope : MonoBehaviour
|
||||
[Header("Head Segment Clamp")] [Tooltip("第一段(起点->第1节点)允许的最小长度,避免收线时第一段被压到0导致数值炸")] [SerializeField, Min(0.0001f)]
|
||||
private float headMinLen = 0.01f;
|
||||
|
||||
|
||||
[Header("Collision Filter")]
|
||||
[SerializeField, Tooltip("只对这些Layer进行物理检测(Raycast/SphereCast等)。不在这里的层完全不检测。")]
|
||||
private LayerMask collisionMask = ~0;
|
||||
|
||||
[Header("Simple Ground/Water Constraint (Cheap)")] [SerializeField]
|
||||
private bool constrainToGround = true;
|
||||
|
||||
@@ -116,6 +121,10 @@ public class Rope : MonoBehaviour
|
||||
maxPhysicsNodes = Mathf.Max(maxPhysicsNodes, minPhysicsNodes);
|
||||
|
||||
headMinLen = Mathf.Max(headMinLen, 0.0001f);
|
||||
|
||||
// 如果你希望只用一个mask控制,避免 groundMask 忘了配
|
||||
if (groundMask == ~0)
|
||||
groundMask = collisionMask;
|
||||
}
|
||||
|
||||
private void InitLengthSystem()
|
||||
@@ -129,12 +138,13 @@ public class Rope : MonoBehaviour
|
||||
private void AllocateAndInitNodes()
|
||||
{
|
||||
// 若锚点存在:最小长度就是两锚点直线距离 + minSlack(防抖)
|
||||
if (startAnchor && endAnchor)
|
||||
{
|
||||
float minFeasible = Vector3.Distance(startAnchor.position, endAnchor.position) + minSlack;
|
||||
currentLength = Mathf.Max(currentLength, minFeasible);
|
||||
targetLength = Mathf.Max(targetLength, minFeasible);
|
||||
}
|
||||
// if (startAnchor && endAnchor)
|
||||
// {
|
||||
// float minFeasible = Vector3.Distance(startAnchor.position, endAnchor.position) + minSlack;
|
||||
// minFeasible -= 0.2f;
|
||||
// currentLength = Mathf.Max(currentLength, minFeasible);
|
||||
// targetLength = Mathf.Max(targetLength, minFeasible);
|
||||
// }
|
||||
|
||||
physicsNodes = Mathf.Clamp(ComputeDesiredNodes(currentLength), 2, maxPhysicsNodes);
|
||||
pCurr = new Vector3[physicsNodes];
|
||||
@@ -170,12 +180,7 @@ public class Rope : MonoBehaviour
|
||||
{
|
||||
targetLength = Mathf.Max(0f, lengthMeters);
|
||||
}
|
||||
|
||||
/// <summary>增加/减少目标总长度(米)。正数放线,负数收线。</summary>
|
||||
public void AddTargetLength(float deltaMeters)
|
||||
{
|
||||
SetTargetLength(targetLength + deltaMeters);
|
||||
}
|
||||
|
||||
|
||||
public float GetCurrentLength() => currentLength;
|
||||
public float GetTargetLength() => targetLength;
|
||||
@@ -224,8 +229,9 @@ public class Rope : MonoBehaviour
|
||||
|
||||
private void UpdateLengthSmooth()
|
||||
{
|
||||
float anchorDist = Vector3.Distance(startAnchor.position, endAnchor.position);
|
||||
float minFeasible = anchorDist + minSlack;
|
||||
// float anchorDist = Vector3.Distance(startAnchor.position, endAnchor.position);
|
||||
// float minFeasible = anchorDist + minSlack;
|
||||
float minFeasible = 0.01f;
|
||||
|
||||
// ✅ 最小长度 = 起点终点直线距离(+slack),最大不限制
|
||||
float desired = Mathf.Max(targetLength, minFeasible);
|
||||
@@ -396,6 +402,8 @@ public class Rope : MonoBehaviour
|
||||
|
||||
private void ConstrainToGroundAndWater()
|
||||
{
|
||||
int groundLayerMask = collisionMask & groundMask; // ✅ 统一过滤:只检测指定层
|
||||
|
||||
for (int i = 1; i < physicsNodes - 1; i++)
|
||||
{
|
||||
Vector3 p = pCurr[i];
|
||||
@@ -406,10 +414,10 @@ public class Rope : MonoBehaviour
|
||||
if (p.y < minY) p.y = minY;
|
||||
}
|
||||
|
||||
if (constrainToGround)
|
||||
if (constrainToGround && groundLayerMask != 0)
|
||||
{
|
||||
Vector3 origin = p + Vector3.up * groundCastHeight;
|
||||
if (Physics.Raycast(origin, Vector3.down, out RaycastHit hit, groundCastDistance, groundMask,
|
||||
if (Physics.Raycast(origin, Vector3.down, out RaycastHit hit, groundCastDistance, groundLayerMask,
|
||||
QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
float minY = hit.point.y + groundRadius;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NBC;
|
||||
// using Obi;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -87,7 +88,8 @@ namespace NBF
|
||||
|
||||
public void SetObiRopeStretch(float value)
|
||||
{
|
||||
fishingRope.SetTargetLength(value);
|
||||
Log.Error($"SetObiRopeStretch={value}");
|
||||
fishingRope.SetTargetLength(value-0.2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user