private void KeepJumping() { currentJumpStrength -= (gravityDecreasePerSecond * Time.deltaTime); rb.velocity = new Vector2(rb.velocity.x, currentJumpStrength); if (!jumpButtonDown || Time.time - timeStartedJumping >= MaxTimeToHoldJump || IsDead) { JumpingState = JumpingStateEnum.Jumping; } }
private void CheckAndBonk() { if (JumpingState == JumpingStateEnum.Start && CheckIsUnderCeiling()) { Play(gameObject, LandSound); JumpingState = JumpingStateEnum.Jumping; rb.velocity = new Vector2(rb.velocity.x, 0); rb.position = new Vector2(rb.position.x, Mathf.Round(rb.position.y) - 2f); } }
private void HandleJumpState() { CheckAndBonk(); if (JumpingState == JumpingStateEnum.Start) { KeepJumping(); } if (JumpingState == JumpingStateEnum.Jumping) { if (isOnFloor) { JumpingState = JumpingStateEnum.NotJumping; } } }
public void Jump() { if (IsDead) { return; } var canJump = (isOnFloor && JumpingState == JumpingStateEnum.NotJumping) || (canCoyoteJump && !isOnFloor); if (!canJump) { return; } Play(gameObject, JumpSound); JumpingState = JumpingStateEnum.Start; timeStartedJumping = Time.time; currentJumpStrength = JumpHoldStrength; }