From d1ae9ecd4479a7a781f59b69dfc7311df1970378 Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Sun, 16 Jun 2024 14:20:15 +0800 Subject: [PATCH] loop kina fix --- src/Mechanics/AvatarNavigator.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Mechanics/AvatarNavigator.cpp b/src/Mechanics/AvatarNavigator.cpp index 1ef2c01..4e30cb0 100644 --- a/src/Mechanics/AvatarNavigator.cpp +++ b/src/Mechanics/AvatarNavigator.cpp @@ -6,6 +6,7 @@ std::deque AvatarNavigator::findPath(glm::vec2 currentcell, glm::vec2 destinationcell) { + glm::vec2 ogcell = currentcell; std::deque dirQue; if (m_Map->getTileByCellPosition(destinationcell)->getWalkable() == false) { return dirQue; @@ -14,7 +15,7 @@ std::deque AvatarNavigator::findPath(glm::vec2 currentcell, Side whichSideToTouchObstacle = randomlyChooseSide(); int count = 0; - while (currentcell != destinationcell && count < 100) { + while (currentcell != destinationcell && count < 10) { printf("(findPath)\n"); count++; std::vector staightDirque; @@ -48,6 +49,9 @@ std::deque AvatarNavigator::findPath(glm::vec2 currentcell, for (auto i : movealong) { dirQue.push_back(i); currentcell = PathUtility::getNextCellByCurrent(i, currentcell); + if (ogcell == currentcell) { + return dirQue; + } } } } @@ -58,6 +62,7 @@ std::vector AvatarNavigator::moveAlongsideObstacle(Side side, glm::vec2 currentcell, MoveDirection currentdir, glm::vec2 destinationcell) { + glm::vec2 ogcell = currentcell; std::vector path; while (!canResumeWalkingStraight(currentcell, destinationcell)) { @@ -74,7 +79,7 @@ AvatarNavigator::moveAlongsideObstacle(Side side, glm::vec2 currentcell, path.push_back(currentdir); currentcell = PathUtility::getNextCellByCurrent(currentdir, currentcell); - if (path.size() > 30) { + if (path.size() > 30 || ogcell == currentcell) { return path; } }