Skip to content

Commit

Permalink
loop kina fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Jun 16, 2024
1 parent 8500298 commit d1ae9ec
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Mechanics/AvatarNavigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

std::deque<MoveDirection> AvatarNavigator::findPath(glm::vec2 currentcell,
glm::vec2 destinationcell) {
glm::vec2 ogcell = currentcell;
std::deque<MoveDirection> dirQue;
if (m_Map->getTileByCellPosition(destinationcell)->getWalkable() == false) {
return dirQue;
Expand All @@ -14,7 +15,7 @@ std::deque<MoveDirection> 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<MoveDirection> staightDirque;
Expand Down Expand Up @@ -48,6 +49,9 @@ std::deque<MoveDirection> AvatarNavigator::findPath(glm::vec2 currentcell,
for (auto i : movealong) {
dirQue.push_back(i);
currentcell = PathUtility::getNextCellByCurrent(i, currentcell);
if (ogcell == currentcell) {
return dirQue;
}
}
}
}
Expand All @@ -58,6 +62,7 @@ std::vector<MoveDirection>
AvatarNavigator::moveAlongsideObstacle(Side side, glm::vec2 currentcell,
MoveDirection currentdir,
glm::vec2 destinationcell) {
glm::vec2 ogcell = currentcell;

std::vector<MoveDirection> path;
while (!canResumeWalkingStraight(currentcell, destinationcell)) {
Expand All @@ -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;
}
}
Expand Down

0 comments on commit d1ae9ec

Please sign in to comment.