IEnumerator GoToActionAnim(Node node, MoveStatus status = MoveStatus.rock, Rock rock = null, bool hit = false, Node rockMoveTo = null) { m_animated = true; //float dst; bool jumping = false; float jumpAt = 0; totalDst++; bool inLoseAnim = false; m_transform.rotation = Quaternion.LookRotation((node.worldPosition - m_transform.position), Vector3.up); m_anim.SetFloat("Speed", m_moveSpeed * speedMul); Vector2 nodePos = new Vector2(node.worldPosition.x, node.worldPosition.z); Vector2 antPos; Vector2 startAntPos = new Vector2(m_transform.position.x, m_transform.position.z); float totalDistance = (nodePos - startAntPos).sqrMagnitude - .002f; bool forward = true; //while ((dst = ((antPos = new Vector2(m_transform.position.x, m_transform.position.z)) - nodePos).sqrMagnitude) > .001f) while (forward) { antPos = new Vector2(m_transform.position.x, m_transform.position.z); if ((startAntPos - antPos).sqrMagnitude > totalDistance) { forward = false; } //dst = (startAntPos - antPos).sqrMagnitude - (nodePos - startAntPos).sqrMagnitude; SoundManager.inst.PlayFoot(speedMul); float dstNsqr = (antPos - nodePos).magnitude; if (!inLoseAnim) { if (rock != null) //rock anim { if (hit) { if (dstNsqr < Grid.inst.nodeRadius * 1.8f) { rock.Hit(rockMoveTo, m_moveSpeed); rock = null; } } else if (dstNsqr < Grid.inst.nodeRadius * 1f) { rock.Broke(m_transform.forward); rock = null; } } if (jumping) { if (dstNsqr < jumpAt) { jumping = false; m_anim.SetBool("Jump", false); } } else { float jump = -1; foreach (float j in jumpdst) { if (dstNsqr < (totalDst - (j + .55f)) * Grid.inst.nodeRadius * 2) { m_anim.SetBool("Jump", true); m_anim.SetTrigger("JumpTrigger"); jumping = true; jump = j; jumpAt = ((totalDst - (j + 1.1f))) * Grid.inst.nodeRadius * 2; SoundManager.inst.PlayJump(); } } if (jump != -1) { jumpdst.Remove(jump); } } if (status == MoveStatus.cactus) { if (dstNsqr < .6f * Grid.inst.nodeRadius * 2) { inLoseAnim = true; totalDistance -= .1f; Debug.Log("cactus anim"); } } else if (status == MoveStatus.pit) { if (dstNsqr < .4f * Grid.inst.nodeRadius * 2) { inLoseAnim = true; totalDistance -= .1f; Debug.Log("pit anim"); } } } else { if (status == MoveStatus.pit) { float y = Mathf.Lerp(m_transform.position.y, -.6f, 1 - (dstNsqr / .4f)); m_transform.position = new Vector3(m_transform.position.x, y, m_transform.position.z); } } m_transform.position += ((node.worldPosition - m_transform.position).normalized * Time.deltaTime * m_moveSpeed * speedMul); yield return(null); } m_transform.position = new Vector3(node.worldPosition.x, m_transform.position.y, node.worldPosition.z); crtNode = node; speedMul = 1f; m_anim.SetFloat("Speed", 0); m_anim.SetBool("Jump", false); m_animated = false; CheckVictoryCollectibles(node); GameManager.inst.CallEndTurn(); }