提交
This commit is contained in:
@@ -64,18 +64,23 @@ public class ClawMachineController : MonoBehaviour
|
||||
|
||||
// 3. 下降
|
||||
yield return Descend();
|
||||
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
// 4. 再次调整抓钩
|
||||
//yield return AdjustClawsForGrab();
|
||||
yield return AdjustClawsForGrab();
|
||||
|
||||
// 5. 抓取目标
|
||||
//currentTarget.SetParent(transform);
|
||||
currentTarget.SetParent(transform);
|
||||
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
// 6. 上升
|
||||
//yield return Ascend();
|
||||
yield return Ascend();
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
// 7. 返回初始位置
|
||||
//yield return ReturnToInitialPosition();
|
||||
yield return ReturnToInitialPosition();
|
||||
|
||||
isGrabbing = false;
|
||||
isMoving = false;
|
||||
@@ -83,6 +88,14 @@ public class ClawMachineController : MonoBehaviour
|
||||
|
||||
private IEnumerator MoveToPosition(Vector3 targetPos)
|
||||
{
|
||||
if (currentTarget == null) yield break;
|
||||
|
||||
SpriteRenderer targetSprite = currentTarget.GetComponent<SpriteRenderer>();
|
||||
if (targetSprite == null) yield break;
|
||||
float targetLeft = targetSprite.bounds.min.x;
|
||||
float targetRight = targetSprite.bounds.max.x;
|
||||
|
||||
targetPos.x=(targetLeft+targetRight)/2;
|
||||
float distance = Vector3.Distance(transform.position, targetPos);
|
||||
float duration = distance / moveSpeed;
|
||||
|
||||
@@ -97,24 +110,22 @@ public class ClawMachineController : MonoBehaviour
|
||||
SpriteRenderer targetSprite = currentTarget.GetComponent<SpriteRenderer>();
|
||||
if (targetSprite == null) yield break;
|
||||
|
||||
// 计算目标上边沿位置
|
||||
// 计算目标边界
|
||||
float targetTop = targetSprite.bounds.max.y;
|
||||
float currentTop = topEdge.position.y;
|
||||
float targetLeft = targetSprite.bounds.min.x;
|
||||
|
||||
// 计算需要移动的距离
|
||||
float moveDistance = targetTop - currentTop + grabOffset;
|
||||
|
||||
// 调整位置使上边沿接近目标上边沿
|
||||
|
||||
float topOffset = targetTop - topEdge.position.y + 0.5f; // 确保上边沿高于目标
|
||||
float leftOffset = leftClaw.position.x -(targetLeft-0.5f); // 确保左爪超出目标左边界
|
||||
|
||||
// 调整位置
|
||||
Vector3 newPos = transform.position;
|
||||
newPos.y += moveDistance;
|
||||
newPos.y += topOffset;
|
||||
yield return MoveToPosition(newPos);
|
||||
|
||||
// 调整爪子位置
|
||||
float targetWidth = targetSprite.bounds.size.x;
|
||||
float currentWidth = Vector3.Distance(leftClaw.position, rightClaw.position);
|
||||
|
||||
// 计算需要的爪子伸缩量
|
||||
float extendAmount = (targetWidth + grabOffset * 2) - currentWidth;
|
||||
float extendAmount=leftOffset;
|
||||
|
||||
yield return ExtendClaws(extendAmount);
|
||||
}
|
||||
|
||||
@@ -134,11 +145,22 @@ public class ClawMachineController : MonoBehaviour
|
||||
SpriteRenderer targetSprite = currentTarget.GetComponent<SpriteRenderer>();
|
||||
if (targetSprite == null) yield break;
|
||||
|
||||
// 计算目标宽度
|
||||
float targetWidth = targetSprite.bounds.size.x;
|
||||
// 计算目标边界
|
||||
float targetTop = targetSprite.bounds.max.y;
|
||||
float targetLeft = targetSprite.bounds.min.x;
|
||||
|
||||
// 调整爪子位置以卡住边缘
|
||||
float extendAmount = targetWidth + grabOffset;
|
||||
|
||||
// float topOffset = targetTop - topEdge.position.y + grabOffset; // 确保上边沿高于目标
|
||||
float leftOffset = leftClaw.position.x -(targetLeft-grabOffset); // 确保左爪超出目标左边界
|
||||
|
||||
// 调整位置
|
||||
// Vector3 newPos = transform.position;
|
||||
// newPos.y += topOffset;
|
||||
// yield return MoveToPosition(newPos);
|
||||
|
||||
// 调整爪子位置
|
||||
float extendAmount=leftOffset;
|
||||
|
||||
yield return ExtendClaws(extendAmount);
|
||||
}
|
||||
|
||||
@@ -147,10 +169,10 @@ public class ClawMachineController : MonoBehaviour
|
||||
Vector3 leftTarget = leftClaw.localPosition;
|
||||
Vector3 rightTarget = rightClaw.localPosition;
|
||||
|
||||
leftTarget.x -= amount / 2;
|
||||
rightTarget.x += amount / 2;
|
||||
leftTarget.x -= amount;
|
||||
rightTarget.x += amount;
|
||||
|
||||
float duration = amount / clawExtendSpeed;
|
||||
float duration = Mathf.Abs(amount) / clawExtendSpeed;
|
||||
|
||||
leftClaw.DOLocalMove(leftTarget, duration).SetEase(Ease.Linear);
|
||||
rightClaw.DOLocalMove(rightTarget, duration).SetEase(Ease.Linear);
|
||||
|
||||
Reference in New Issue
Block a user