IEnumerator AttackComplete() { animation.SetBool("IsRushing", true); //Debug.Log("Rushing should be true here"); bool isPlayerHit = false; bool isSomethingHit = false; //Vector3 targetOldPosition = AIPath.destination; Vector2 targetOldPosition = targetObj.transform.position; Vector2 rayDirection = targetOldPosition - (Vector2)transform.position; Vector2 minoOldPosition = transform.position; Vector3 chargeTarget; RaycastHit2D rayHit = Physics2D.Raycast((Vector2)transform.position, rayDirection, Mathf.Infinity, g_layerMask); if (rayHit.collider != null) { Debug.DrawRay(transform.position, rayHit.point - (Vector2)transform.position, Color.red, 1f); } else { Debug.DrawRay(transform.position, targetOldPosition - (Vector2)transform.position, Color.blue, 1f); } if (rayHit.collider != null) { chargeTarget = (Vector3)rayHit.point; Debug.Log("Collider hit is:" + rayHit.collider.gameObject.name); } else { Debug.Log("Collider was f*****g NULL!"); chargeTarget = targetOldPosition; //isAttacking = false; //AIPath.canSearch = true; //yield break; } while (!isSomethingHit) { //Vector3 smoothedDelta = Vector3.MoveTowards(transform.position, chargeTarget, Time.fixedDeltaTime * g_rushSpeed); //rb.MovePosition((Vector2)smoothedDelta) //Debug.Log(transform.name + "Therefore: ChargeTar:" + chargeTarget + "And transform.position:" + transform.position); Vector2 velocity = (chargeTarget - transform.position); //Debug.Log("Velocity:" + velocity); velocity *= g_rushSpeed; rb.AddForce(velocity, ForceMode2D.Force); //animation.SetBool("IsCharging", false); Collider2D[] hitColliders = Physics2D.OverlapBoxAll(box.transform.position, 1.4f * box.size, 0f); //Debug.Log("The list is size: " + hitColliders.Length); foreach (Collider2D hit in hitColliders) { Debug.Log("Hit collider name: " + hit.gameObject.name); } foreach (Collider2D hit in hitColliders) { if (hit.CompareTag("Shield")) { if (hit.enabled) { Debug.Log(transform.name + "Shield Detected!"); hitShield = true; break; } else { Debug.Log(transform.name + "Shield not Detected!"); hitShield = false; break; } } } foreach (Collider2D hit in hitColliders) { minoScript = hit.gameObject.GetComponent <MinotaurAI>(); if (hit.CompareTag("Player") && !hitShield) { Debug.Log(transform.name + "Player hit" + hit.gameObject.name); animation.SetBool("IsRushing", false); //animation.SetBool("IsMoving", false); CinemachineShake.Instance.ShakeCamera(10f, .3f); SFX.GetComponent <SFX>().PlaySwordSwing(); isPlayerHit = true; isSomethingHit = true; GameManager.Instance.updateHP(-attackDamage); } else if (hitShield) { Debug.Log(transform.name + "Shield hit" + hit.gameObject.name); animation.SetBool("IsRushing", false); //animation.SetBool("IsMoving", false); CinemachineShake.Instance.ShakeCamera(10f, .3f); isPlayerHit = true; isSomethingHit = true; } else if (hit.gameObject.layer == LayerMask.NameToLayer("Obstacles")) { Debug.Log(transform.name + "hit something" + hit.gameObject.name); animation.SetBool("IsRushing", false); //animation.SetBool("IsMoving", false); CinemachineShake.Instance.ShakeCamera(10f, .3f); rb.velocity = new Vector2(0f, 0f); //rb.AddForce(rayDirection.normalized * -100f); Vector2 closestPt = hit.ClosestPoint(transform.position); Vector2 vecAway = ((Vector2)transform.position - closestPt).normalized; rb.AddForce(vecAway * 100f); isSomethingHit = true; } //You da issue else if (hit.tag == "Enemy" && minoScript == null) { Debug.Log(transform.name + "Hit enemy tag of name" + hit.gameObject.name); animation.SetBool("IsRushing", false); //animation.SetBool("IsMoving", false); rb.velocity = new Vector2(0f, 0f); isSomethingHit = true; //Debug.DrawRay(transform.position, (Vector2)(hit.transform.position - transform.position), Color.blue, 10f); //hit.attachedRigidbody.transform.position = transform.position; } else if (hit.tag == "Enemy" && minoScript != null) { Rigidbody2D colRB = hit.gameObject.GetComponent <Rigidbody2D>(); //Debug.Log(transform.name + "Hit enemy tag of name" + hit.gameObject.name + "Minoscript found."); //Debug.Log(transform.name + " velcity mag. is :" + rb.velocity.magnitude); //Debug.Log("And the collision's velcity is: " + colRB.velocity.magnitude); if ((rb.velocity.magnitude - colRB.velocity.magnitude > 0.05f) && colRB.velocity.magnitude > 0.001f) { animation.SetBool("IsRushing", false); rb.velocity = new Vector2(0f, 0f); isSomethingHit = true; } //animation.SetBool("IsRushing", false); //animation.SetBool("IsMoving", false); //rb.velocity = new Vector2(0f, 0f); //isSomethingHit = true; } //StartCoroutine("stuck"); } hitShield = false; yield return(null); } AIPath.canSearch = true; if (isPlayerHit) { yield return(new WaitForSeconds(.75f * stunnedTime)); rb.velocity = new Vector2(0, 0); rb.transform.Translate(-1 * rayDirection.normalized); yield return(new WaitForSeconds(.25f * stunnedTime)); AIPath.canMove = true; } else { yield return(new WaitForSeconds(stunnedTime)); AIPath.canMove = true; } isAttacking = false; }