|
|
|
@ -16,6 +16,11 @@ public class PlayerPathRunner : MonoBehaviour
|
|
|
|
|
public bool useTapToMove = true;
|
|
|
|
|
public float tapWindowSeconds = 0.5f;
|
|
|
|
|
|
|
|
|
|
[Header("Jump Settings")]
|
|
|
|
|
public float jumpPower = 2f;
|
|
|
|
|
public float jumpDuration = 0.5f;
|
|
|
|
|
public float jumpDistance = 3f; // Distance in world units
|
|
|
|
|
|
|
|
|
|
[Header("Path Setup")]
|
|
|
|
|
public DOTweenPath pathSource;
|
|
|
|
|
|
|
|
|
@ -27,6 +32,8 @@ public class PlayerPathRunner : MonoBehaviour
|
|
|
|
|
private float pathPosition = 0f;
|
|
|
|
|
private Vector3[] drawPoints;
|
|
|
|
|
private Path bakedPath;
|
|
|
|
|
private bool isJumping = false;
|
|
|
|
|
private System.Action onJumpComplete;
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
@ -64,6 +71,9 @@ public class PlayerPathRunner : MonoBehaviour
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
// Don't process normal movement if jumping
|
|
|
|
|
if (isJumping) return;
|
|
|
|
|
|
|
|
|
|
if (useTapToMove)
|
|
|
|
|
{
|
|
|
|
|
HandleInput();
|
|
|
|
@ -104,7 +114,12 @@ public class PlayerPathRunner : MonoBehaviour
|
|
|
|
|
pathPosition += speed * Time.deltaTime;
|
|
|
|
|
pathPosition %= 1f;
|
|
|
|
|
|
|
|
|
|
float floatIndex = pathPosition * (drawPoints.Length - 1);
|
|
|
|
|
UpdatePositionOnPath(pathPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdatePositionOnPath(float normalizedPosition)
|
|
|
|
|
{
|
|
|
|
|
float floatIndex = normalizedPosition * (drawPoints.Length - 1);
|
|
|
|
|
int iA = Mathf.FloorToInt(floatIndex);
|
|
|
|
|
int iB = Mathf.Min(iA + 1, drawPoints.Length - 1);
|
|
|
|
|
float t = floatIndex - iA;
|
|
|
|
@ -113,8 +128,67 @@ public class PlayerPathRunner : MonoBehaviour
|
|
|
|
|
transform.position = pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void TriggerJump(System.Action onComplete = null)
|
|
|
|
|
{
|
|
|
|
|
if (isJumping) return;
|
|
|
|
|
|
|
|
|
|
Debug.Log("🦘 Jump triggered in PlayerPathRunner!");
|
|
|
|
|
isJumping = true;
|
|
|
|
|
onJumpComplete = onComplete;
|
|
|
|
|
|
|
|
|
|
// Calculate how much to advance on the path based on world distance
|
|
|
|
|
float pathLength = CalculateTotalPathLength();
|
|
|
|
|
float jumpPercentage = jumpDistance / pathLength;
|
|
|
|
|
|
|
|
|
|
// Calculate end position on path
|
|
|
|
|
float targetPathPosition = pathPosition + jumpPercentage;
|
|
|
|
|
targetPathPosition %= 1f; // Wrap around if needed
|
|
|
|
|
|
|
|
|
|
// Get world positions for start and end
|
|
|
|
|
Vector3 startPos = transform.position;
|
|
|
|
|
Vector3 endPos = GetWorldPositionAtPathPosition(targetPathPosition);
|
|
|
|
|
|
|
|
|
|
// Do the jump
|
|
|
|
|
transform.DOJump(endPos, jumpPower, 1, jumpDuration)
|
|
|
|
|
.SetEase(Ease.OutQuad)
|
|
|
|
|
.OnComplete(() => {
|
|
|
|
|
// Update our path position to match where we jumped to
|
|
|
|
|
pathPosition = targetPathPosition;
|
|
|
|
|
isJumping = false;
|
|
|
|
|
|
|
|
|
|
Debug.Log("Jump completed!");
|
|
|
|
|
onJumpComplete?.Invoke();
|
|
|
|
|
onJumpComplete = null;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float CalculateTotalPathLength()
|
|
|
|
|
{
|
|
|
|
|
float totalLength = 0f;
|
|
|
|
|
for (int i = 0; i < drawPoints.Length - 1; i++)
|
|
|
|
|
{
|
|
|
|
|
totalLength += Vector3.Distance(drawPoints[i], drawPoints[i + 1]);
|
|
|
|
|
}
|
|
|
|
|
return totalLength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3 GetWorldPositionAtPathPosition(float normalizedPos)
|
|
|
|
|
{
|
|
|
|
|
float floatIndex = normalizedPos * (drawPoints.Length - 1);
|
|
|
|
|
int iA = Mathf.FloorToInt(floatIndex);
|
|
|
|
|
int iB = Mathf.Min(iA + 1, drawPoints.Length - 1);
|
|
|
|
|
float t = floatIndex - iA;
|
|
|
|
|
|
|
|
|
|
return Vector3.Lerp(drawPoints[iA], drawPoints[iB], t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetCurrentSpeed()
|
|
|
|
|
{
|
|
|
|
|
return currentSpeed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsJumping()
|
|
|
|
|
{
|
|
|
|
|
return isJumping;
|
|
|
|
|
}
|
|
|
|
|
}
|