小问题修复,优化切割手感
This commit is contained in:
@@ -410,10 +410,21 @@ public class GearFollower : MonoBehaviour
|
||||
Vector2 toMouse = (mousePos - from).normalized;
|
||||
float angle = Vector2.SignedAngle(forward, toMouse);
|
||||
|
||||
if (Mathf.Abs(angle) > 120f)
|
||||
// 优化:计算当前段的角度,判断是否为尖角
|
||||
int prevIndex = WrapIndex(currentEdgeIndex - tractionDirection);
|
||||
Vector2 prevPoint = edgePoints[prevIndex];
|
||||
Vector2 prevSegment = (from - prevPoint).normalized;
|
||||
float segmentAngle = Vector2.Angle(prevSegment, forward);
|
||||
bool isSharpCorner = segmentAngle > 60f; // 夹角大于60度认为是尖角
|
||||
|
||||
// 动态调整方向切换阈值和冷却时间
|
||||
float switchAngleThreshold = isSharpCorner ? 90f : 120f;
|
||||
float currentCooldown = isSharpCorner ? 0.05f : directionSwitchCooldown;
|
||||
|
||||
if (Mathf.Abs(angle) > switchAngleThreshold)
|
||||
{
|
||||
directionSwitchTimer += Time.deltaTime;
|
||||
if (directionSwitchTimer > directionSwitchCooldown)
|
||||
if (directionSwitchTimer > currentCooldown)
|
||||
{
|
||||
tractionDirection *= -1;
|
||||
directionSwitchTimer = 0f;
|
||||
@@ -433,7 +444,9 @@ public class GearFollower : MonoBehaviour
|
||||
Vector2 moveDir = (targetPoint - gearPos);
|
||||
float distance = moveDir.magnitude;
|
||||
|
||||
float maxStep = tractionSpeed * Time.deltaTime;
|
||||
// 动态调整牵引速度:在尖角处提速
|
||||
float speedMultiplier = isSharpCorner ? 1.5f : 1.0f;
|
||||
float maxStep = tractionSpeed * speedMultiplier * Time.deltaTime;
|
||||
|
||||
if (distance <= maxStep)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user