public void Dash(PlayerLightRadius playerLight, float rangeTarget) { if (!isDashing) { CharAnimator.SetInteger("State", IDLE); StartCoroutine(DashCoroutine(input, playerLight, rangeTarget)); } }
private IEnumerator DashCoroutine(Vector2 direction, PlayerLightRadius playerLight, float rangeTarget) { isDashing = true; playerLight.ShouldDecay = false; float lightDecayRate = (playerLight.GetRange() - rangeTarget) / dashDuration; Rigid.velocity = Vector2.zero; float speed = dashSpeed; Vector2 normDirection = direction.normalized; float dashTime = 0.0f; while (dashTime < dashDuration) { CharAnimator.SetInteger("State", IDLE); Rigid.velocity = speed * direction; speed = Mathf.Abs(dashSpeed - (dashDecay * dashTime * dashTime)); // quadratic decay dashTime += Time.deltaTime; playerLight.AdjustRange(-1 * Time.deltaTime * lightDecayRate); yield return(new WaitForFixedUpdate()); } Rigid.velocity = Vector2.zero; playerLight.ShouldDecay = true; isDashing = false; }