diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index dd2abe5..3c7dc7f 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -101,7 +101,7 @@ public class PlayerMovement : MonoBehaviour if (!IsJumping) { //Ground Check - if (Physics2D.OverlapBox(this.transform.position, _groundCheckSize, 0, _groundLayer) && !IsJumping) //checks if set box overlaps with ground + if (IsGrounded()) //checks if set box overlaps with ground { LastOnGroundTime = Data.coyoteTime; //if so sets the lastGrounded to coyoteTime trumpet = true; @@ -151,6 +151,13 @@ public class PlayerMovement : MonoBehaviour _isJumpCut = false; _isJumpFalling = false; Jump(); + if (!IsGrounded() && in_range && trumpet) { + Destroy(enemy.gameObject); + enemy = null; + in_range = false; + } else if (!IsGrounded() && !in_range && trumpet) { + trumpet = false; + } } //WALL JUMP // else if (CanWallJump() && LastPressedJumpTime > 0) @@ -209,6 +216,7 @@ public class PlayerMovement : MonoBehaviour SetGravityScale(Data.gravityScale); } #endregion + } } private void FixedUpdate() @@ -380,6 +388,9 @@ public class PlayerMovement : MonoBehaviour private bool CanJump() { + if (!IsGrounded() && trumpet) { + return true; + } return LastOnGroundTime > 0 && !IsJumping; } @@ -406,6 +417,10 @@ public class PlayerMovement : MonoBehaviour else return false; } + + public bool IsGrounded() { + return (Physics2D.OverlapBox(this.transform.position, _groundCheckSize, 0, _groundLayer) && !IsJumping); + } #endregion