private IEnumerator FollowFoundPath() { int currentIndex = 0; bool exitPathFollow = false; float timeAtSamePos = 0.0f; Vector2 lasPost = transform.position; while (currentIndex < m_path.PathSize) { Vector2 currentAgentPos = transform.position; while (m_path.HasCrossedNode(currentIndex, currentAgentPos)) { currentIndex++; if (currentIndex == m_path.PathSize) { exitPathFollow = true; break; } } if (exitPathFollow || timeAtSamePos >= StuckTime) { break; } if (lasPost == (Vector2)transform.position) { timeAtSamePos += Time.deltaTime; } else { timeAtSamePos = 0.0f; } lasPost = transform.position; Vector2 targetDir = m_path.GetNodePos(currentIndex) - m_path.GetNodePos(currentIndex - 1); Vector2 currentPlayerDir = m_path.GetDirToNodeFrom(currentIndex, currentAgentPos); Vector2 dir = Vector2.Lerp(currentPlayerDir, targetDir, Time.deltaTime * turnSpeed).normalized; if (dir.sqrMagnitude == 0) { m_characterScript.SetMovementStatus(Character.MovementStatus.None); } else { m_characterScript.SetMovementStatus(Character.MovementStatus.Walk); } m_characterScript.SetDirection(dir); //Wait until next frame yield return(null); } currentIndex = 0; m_characterScript.SetDirection(new Vector2(0, 0)); m_characterScript.SetMovementStatus(Character.MovementStatus.None); m_path = null; m_startWaitingTime = Time.time; }