How to prevent character from getting stuck?

Started by jumpjack, Wed 04/01/2023 10:34:04

Previous topic - Next topic

jumpjack

Sometimes it happens that my character moves to a location where it cannot move away anymore, nor by mouse neither by keyboard. Apparently if walks to a nonwalkable area, and it can't get out anymore.
I don't know how it can get there, but once it happens, how can I unlock it? How can I "undo" the character to previous position upon detecting no further possible moves?

Notes:
- V. 3.6.0 RC4
- character is not at room edge
-  I am not using "adjust speed" or "scaling"
- room is static, not scrolling


edit:
I don't know if this can help, anyway I logged these positions before character getting stuck:
(w and w are walkable area in current screen/room position)

2023/01/04 12:09:21 - x,y,w,w = 164,83,1,1
2023/01/04 12:09:21 - x,y,w,w = 168,85,1,1
2023/01/04 12:09:21 - x,y,w,w = 171,86,1,1
2023/01/04 12:09:21 - x,y,w,w = 174,85,1,1
2023/01/04 12:09:21 - x,y,w,w = 178,83,1,1
2023/01/04 12:09:21 - x,y,w,w = 175,80,0,0

Here I even detected a move inside a non-walkable area:

2023/01/04 12:09:21 - x,y,w,w = 170,86,1,1
2023/01/04 12:09:21 - x,y,w,w = 173,82,1,1
2023/01/04 12:09:21 - x,y,w,w = 177,80,1,1
2023/01/04 12:09:21 - x,y,w,w = 178,79,1,1
2023/01/04 12:09:21 - x,y,w,w = 175,80,0,0
2023/01/04 12:09:21 - x,y,w,w = 171,82,0,0

I implemented this "emergency function" which brings the character back to last valid position while saving debug data previously logged:

Code: ags
   if (GetWalkableAreaAtRoom(  player.x,  player.y) == 0) {
    for (int index=0; index < 1000; index++) {
      //debugPrint(String.Format("x,y,w,w = %d,%d,%d,%d",  prevXarr[index],  prevYarr[index],  prevWarr[index],  prevW2arr[index]), false);
      if (prevWarr[index] !=0) {
        player.x = prevXarr[index];
        player.y = prevYarr[index];
      }
    }
  }

I put it inside repeatedly_execute() in global script: given that in no case the character is allowed to be into a nonwalkable position, as soon this condition is detected, the position is brought back to last valid one. I don't know if this is the best method, or if it would be better to just call cEgo.PlaceOnWalkableArea() upon detecting character on forbidden position, but I wanted to log the positions which led to the wrong position.

Khris

The pathfinding algorithm shouldn't move the character outside a walkable area, ever.
How are you moving the character exactly? Standard WalkTo clicks / keyboard movement only?

Crimson Wizard

#2
If this is what actually happens, then it of course should be considered an engine bug. I would separate solving the bug and workarounds; and I'm mostly interested in the bug details atm. There's a ticket opened about same problem: https://github.com/adventuregamestudio/ags/issues/1879
Ideally we'd need a walkable mask, and an example of starting position / Walk command arguments which causes character to stuck. This would help to reproduce and diagnose the problem.

jumpjack

Quote from: Crimson Wizard on Wed 04/01/2023 15:28:24If this is what actually happens, then it of course should be considered an engine bug. I would separate solving the bug and workarounds; and I'm mostly interested in the bug details atm. There's a ticket opened about same problem: https://github.com/adventuregamestudio/ags/issues/1879
Ideally we'd need a walkable mask, and an example of starting position / Walk command arguments which causes character to stuck. This would help to reproduce and diagnose the problem.
Yes, that is MY ticket. :-)
I just attached there the game and the mask.

eri0o

I see you are using that keyboard module that comes with the template. That control is quite unnatural when compared to more modern games. I think the controls from my Controlz module would work better for the isometric world, specially if your character is designed with 8 directions.

jumpjack

Thanks. I already modified the original script, which moved character horizontally and vertically, but I needed diagonal moves.
My character has only 4 directions, unlike the one in the demo, which I am currently still using.

SMF spam blocked by CleanTalk