Jump configured

dev-hazim
Hazim 1 month ago
parent b03b3d8daf
commit c82fee9074

@ -97,30 +97,36 @@ public class HurdleManager : MonoBehaviour
}
}
void CountTaps()
{
if (Input.GetMouseButtonDown(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began))
{
currentTapCount++;
Debug.Log($"Tap {currentTapCount}/{requiredTaps}");
}
}
void CheckForJump()
{
if (currentHurdle == null) return;
if (currentHurdle == null || playerRunner.IsJumping()) return;
float remainingDistance = GetRemainingDistance(playerRunner.transform.position, currentHurdle.position);
// When very close to hurdle
if (remainingDistance < 1f && challengeCompleted)
// When very close to hurdle and challenge is completed
if (remainingDistance < 5f && challengeCompleted)
{
// Trigger jump in the PlayerPathRunner
playerRunner.TriggerJump(() => {
// This callback runs after jump completes
if (currentHurdle != null)
{
// Trigger jump
TriggerJump();
// Remove hurdle and end challenge after jump
hurdles.Remove(currentHurdle);
if (activeChallenge != null)
StopCoroutine(activeChallenge);
EndChallengeUI();
}
});
}
void TriggerJump()
{
Debug.Log("🦘 JUMP! Player successfully jumped over the hurdle!");
GetComponentInChildren<Animator>().SetTrigger("Jump");
}
void EndChallengeUI()
@ -132,21 +138,12 @@ public class HurdleManager : MonoBehaviour
activeChallenge = null;
}
void CountTaps()
{
if (Input.GetMouseButtonDown(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began))
{
currentTapCount++;
Debug.Log($"Tap {currentTapCount}/{requiredTaps}");
}
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Hurdle"))
{
// Check if this is the current hurdle and challenge wasn't completed
if (other.transform == currentHurdle && !challengeCompleted)
if (other.transform == currentHurdle && !challengeCompleted && !playerRunner.IsJumping())
{
Debug.Log("❌ GAME OVER! Failed to complete tap challenge!");
GameOver();
@ -173,7 +170,7 @@ public class HurdleManager : MonoBehaviour
tapsRequiredText.text = "GAME OVER!";
Debug.Log("💀 GAME OVER - Player failed to clear hurdle!");
GetComponentInChildren<Animator>().enabled = false;
// You can add more game over logic here:
// - Show game over screen
// - Play game over sound
@ -240,6 +237,4 @@ public class HurdleManager : MonoBehaviour
float t = Mathf.Clamp01(Vector3.Dot(point - a, ab) / Vector3.Dot(ab, ab));
return a + t * ab;
}
// Removed the old IsBetween method as it's no longer needed
}

@ -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;
}
}
Loading…
Cancel
Save