diff options
author | Neil Kollack <nkollack@gmail.com> | 2022-04-14 22:27:32 -0500 |
---|---|---|
committer | Neil Kollack <nkollack@gmail.com> | 2022-04-14 22:27:32 -0500 |
commit | 929254005c7dc7437208715a6ae04b69292fe4f7 (patch) | |
tree | 4c543afed0a77d396bd7e35f5f39c4811e355ad8 /Assets/Scripts | |
parent | 80c478b00f090a64ccd63d3252ac02ffa1f7f5a2 (diff) |
feat: player complete + player animation
Diffstat (limited to 'Assets/Scripts')
-rw-r--r-- | Assets/Scripts/Actors/Actor.cs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Assets/Scripts/Actors/Actor.cs b/Assets/Scripts/Actors/Actor.cs index 2e98974..55aed29 100644 --- a/Assets/Scripts/Actors/Actor.cs +++ b/Assets/Scripts/Actors/Actor.cs @@ -21,14 +21,14 @@ namespace MontanaJohns.Actors protected Animator _animator; protected Transform _transform; - public Stats stats; + protected Stats stats; protected Active activeItem; protected bool isGrappling; protected Vector2? grapplePoint = null; protected LayerMask groundLayers; Collection<Item> items; - public int health; + protected int health; protected int jumpCount; protected Vector2 acceleration; @@ -81,8 +81,13 @@ namespace MontanaJohns.Actors public virtual void Jump() { - if (jumpCount++ <= stats.maxJumps) + if(Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayers)) { + jumpCount = stats.maxJumps; + } + if (jumpCount > 0) + { + jumpCount--; _rigidBody.AddForce(Vector2.up * stats.jumpForce); _animator.SetTrigger("jump"); _animator.SetBool("airborn", true); @@ -127,12 +132,11 @@ namespace MontanaJohns.Actors { _animator.SetBool("airborn", true); - while (_rigidBody.velocity.y > 0 || !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayers)) + while (!Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayers)) { - yield return new WaitForFixedUpdate(); + yield return new WaitForEndOfFrame(); } - jumpCount = 0; _animator.SetBool("airborn", false); yield break; |