diff --git a/Assets/Scripts/PlayerBehavior.cs b/Assets/Scripts/PlayerBehavior.cs index 296b22e..19eb6a3 100644 --- a/Assets/Scripts/PlayerBehavior.cs +++ b/Assets/Scripts/PlayerBehavior.cs @@ -24,6 +24,10 @@ public class PlayerBehavior : MonoBehaviour private Vector2 saveVelocity; public bool isInWater = false; public float dashForce = 1.2f; + private float dashTime = 1.0f; + private float dashInc = 0.1f; + private float currentDash = 0.0f; + Vector2 dashVec; [Header("Grappling:")] [SerializeField] public Tutorial_GrapplingGun grapplingGun; @@ -61,6 +65,7 @@ public class PlayerBehavior : MonoBehaviour void Start() { gameUI.UpdateInstrumentUI(); + currentDash = dashTime; } void Update() @@ -95,25 +100,30 @@ public class PlayerBehavior : MonoBehaviour { isDash = true; playerInput.DeactivateInput(); + currentDash = 0.0f; // set so if in water dash will still be true // otherwise turn dash off } - if (!playerController.IsGrounded() && isDash) + if (!playerController.IsGrounded() && isDash && (currentDash < dashTime)) { if (forward == 1) { - Vector2 rightDash = new Vector2(1f, -1f) * dashForce; - _rb.AddForce(rightDash, ForceMode2D.Impulse); + dashVec = new Vector2(1f, -1f) * dashForce; + _rb.AddForce(dashVec, ForceMode2D.Impulse); } else { - Vector2 leftDash = new Vector2(-1f, -1f) * dashForce; - _rb.AddForce(leftDash, ForceMode2D.Impulse); + dashVec = new Vector2(-1f, -1f) * dashForce; + _rb.AddForce(dashVec, ForceMode2D.Impulse); } + currentDash += dashInc; } - else + else if (!isInWater) { isDash = false; + currentDash = 0.0f; + _rb.AddForce(-(dashVec), ForceMode2D.Impulse); + dashVec = Vector2.zero; playerInput.ActivateInput(); } } @@ -221,9 +231,13 @@ public class PlayerBehavior : MonoBehaviour void Bounce() { - Vector2 reflect = new Vector2(saveVelocity.x,-(saveVelocity.y) * bonk); - _rb.AddForce(reflect, ForceMode2D.Impulse); - reflect = Vector2.zero; + if(isDash) + { + Vector2 reflect = new Vector2(saveVelocity.x,-(saveVelocity.y) * bonk); + _rb.AddForce(reflect, ForceMode2D.Impulse); + reflect = Vector2.zero; + } + } void Water()