细分下片段
This commit is contained in:
@@ -63,14 +63,33 @@ public class GearFollower : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
edgePoints = shapePoints
|
||||
.Select(p => (Vector2)targetSpriteRenderer.transform.TransformPoint(p))
|
||||
.ToList();
|
||||
float desiredSegmentLength = 0.1f; // 你可以根据需要调整这个值
|
||||
|
||||
if (edgePoints[0] != edgePoints[edgePoints.Count - 1])
|
||||
edgePoints.Clear();
|
||||
|
||||
for (int i = 0; i < shapePoints.Count; i++)
|
||||
{
|
||||
Vector2 p1 = targetSpriteRenderer.transform.TransformPoint(shapePoints[i]);
|
||||
Vector2 p2 = targetSpriteRenderer.transform.TransformPoint(shapePoints[(i + 1) % shapePoints.Count]);
|
||||
|
||||
float segmentLength = Vector2.Distance(p1, p2);
|
||||
int steps = Mathf.Max(1, Mathf.CeilToInt(segmentLength / desiredSegmentLength));
|
||||
|
||||
for (int s = 0; s < steps; s++)
|
||||
{
|
||||
float t = (float)s / steps;
|
||||
Vector2 interpolated = Vector2.Lerp(p1, p2, t);
|
||||
edgePoints.Add(interpolated);
|
||||
}
|
||||
}
|
||||
|
||||
// 确保闭环
|
||||
if ((edgePoints[0] - edgePoints[edgePoints.Count - 1]).sqrMagnitude > 0.0001f)
|
||||
{
|
||||
edgePoints.Add(edgePoints[0]);
|
||||
}
|
||||
|
||||
Debug.Log($"边缘点数量:{edgePoints.Count}");
|
||||
}
|
||||
|
||||
private void UpdateFollowState(Vector2 mousePos)
|
||||
|
||||
Reference in New Issue
Block a user