IEnumerator Attack() { currentState = State.Attacking; pathfinding.enabled = false; Vector3 originalPos = transform.position; Vector3 targetDirection = (target.position - transform.position).normalized; Vector3 attackPos = target.position - targetDirection * (myCollision); float attackSpeed = 3; float percent = 0; bool didDamage = false; while (percent <= 1) { if (percent >= 0.5f && !didDamage) { didDamage = true; targetVitals.TakeDamage(damage); } percent += Time.deltaTime * attackSpeed; float interpolation = (-Mathf.Pow(percent, 2) + percent) * 4; transform.position = Vector3.Lerp(originalPos, attackPos, interpolation); yield return(null); } currentState = State.Chasing; pathfinding.enabled = true; }