Walkable area border crossing? (SEMI-SOLVED)

Started by WHAM, Sun 14/06/2009 21:45:23

Previous topic - Next topic

WHAM

Hi!

I'm back with a new project, and I seem to be having a small issue.

I have a room with a walkable area mask, as seen below.



In the spots I've boxed, it seems that sometimes (seemingly randomly) my character can walk OFF the walkable area (seemingly by just one pixel) and become stuck. Any ideas on how to solve this?

Also: It seems that I can only have walkable areas and hotspots in 320x200 resolution (the finer areas of the mask are transformed into "blockier" ones when I import them into the game). However, walk-behind masks dont get the same treatment!?
Is this normal, or am I doing something wrong here?

(Using AGS 3.1.2)

Thanks for the help!

EDIT: I've noticed that only lines that Aren't in a precise 90 degree angle but run diagonally (I think that's the word) cause the getting stuck, alongside with corners.
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

GuyAwesome

#1
Could you use something like
Code: ags

// in global or room RepExec
  if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY()) == 0) player.PlaceOnWalkableArea();

It should only be a move of a pixel or so, so it should be massively noticeable when it happens.
Assuming there're no times you WANT the player not to be on a walkable area, but you could turn it on/off with a variable check.

Why it happens in the first place, I couldn't say - maybe changing loops nudges the character just slightly off the walkable area? (Could be related to what Khris mentions here.) I'm just guessing there, but it makes a kind of sense given that yes, that lo-res mask thing is the normal behaviour, IIRC, and it happens mostly on corners/diagonals where the downscaling might be most apparent. Anyway, whyever it happens, it shouldn't stop that code from working. (I hope.)

WHAM

#2
Quote from: GuyAwesome on Sun 14/06/2009 23:05:33
Could you use something like
Code: ags

// in global or room RepExec
  if (GetWalkableAreaAt(player.x-GetViewportX(),player.y-GetViewportY()) == 0) player.PlaceOnWalkableArea();

It should only be a move of a pixel or so, so it should be massively noticeable when it happens.
Assuming there're no times you WANT the player not to be on a walkable area, but you could turn it on/off with a variable check.

Why it happens in the first place, I couldn't say - maybe changing loops nudges the character just slightly off the walkable area? (Could be related to what Khris mentions here.) I'm just guessing there, but it makes a kind of sense given that yes, that lo-res mask thing is the normal behaviour, IIRC, and it happens mostly on corners/diagonals where the downscaling might be most apparent. Anyway, whyever it happens, it shouldn't stop that code from working. (I hope.)

Seems useful, but I tried your code and it didn't help. Which leaves me to wonder, if something else than the character escaping the confines of the walkable area is to blame here? More ideas are welcome, I'll be trying out options until I stop getting stuck... This would be a game-killer bug if I released something this bad... :(

EDIT: Actually, I think there might be something wrong with the code. I made my character say "oh shit" whenever he supposedly walks off a walkable area, and no matter where he stands, he keeps saying it. Even when standing on a walkable area.
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

GuyAwesome

Can you code in some temporary Display lines, to check whether the player is moving off Walkable areas? (Try sticking them in one of the player interactions, and trigger them when the player gets stuck.) If it IS that, then that code should fix it but this way might rule it out for sure. I'm afraid that's it for ideas from me... It could be a related issue, of the pathfinder taking so long to find a valid route that it basically gives up and doesn't move you - but I'm not sure WHAT could cause that to happen.

You said it seems random, but is there some action or sequence that's more likely to cause it? Sorry, kind of clutching at straws now :-\

WHAM

#4
Quote from: GuyAwesome on Sun 14/06/2009 23:31:08
Can you code in some temporary Display lines, to check whether the player is moving off Walkable areas? (Try sticking them in one of the player interactions, and trigger them when the player gets stuck.) If it IS that, then that code should fix it but this way might rule it out for sure. I'm afraid that's it for ideas from me... It could be a related issue, of the pathfinder taking so long to find a valid route that it basically gives up and doesn't move you - but I'm not sure WHAT could cause that to happen.

You said it seems random, but is there some action or sequence that's more likely to cause it? Sorry, kind of clutching at straws now :-\

I'll keep trying to verify the reason this happens. Its not so much random anymore, now that I know what to look for. When I walk near the diagonal edge of a walkable area, I get stuck. Sometimes it happens instantly, sometimes it takes a few clicks to get stuck.

EDIT: Okay, I've now confirmed that my EGO gets out of the walkable areas and ends up on area "0".
The below code makes him say "0 areacode" when he's stuck. Int Areanumber is the number of the area Ego is standing on.

Code: ags
if (timer >= 1) {
  timer = timer - 1;
} else {
  timer = 400;
  cEgo.Say("%i areacode", areanumber);
  cEgo.Say("TIME");
}


I then tried adding:
Code: ags
if (areanumber == 0) {
  player.PlaceOnWalkableArea();
}

into the repeatedly execute function, but nothing happens!

Ideas?

EDIT: It now seems that everything else is clear, except that the "player.PlaceOnWalkableArea();" doesn't do squat. Any alternative ways to force my character to return to a walkable area? Ways to reinforce the code here? Anything?

Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

GuyAwesome

Try replacing player with cEgo. Shouldn't make a lick of difference, but at this point what the hell...
Next, slightly desperate, idea would be to write your own code that finds the nearest walkable area and moves to it. But that's an idea for more awake brain than mine, one which could probably think of something less complicated in the first place :).

WHAM

#6
EDITED: My solution (I must have been too tired to realize even this last night).
RE-EDITED: Simplified the code, removed unnecessary bits.
Code: ags

int walkies = 1;

function repeatedly_execute() {

int areanumber = GetWalkableAreaAt(player.x - GetViewportX(), player.y - GetViewportY());

// When ego walks off a walkable area
if (areanumber == 0) {
// First force him to move one pixel left
  if (walkies == 1) {
  cEgo.Move(cEgo.x - 2, cEgo.y, eBlock, eAnywhere);
  walkies = 0; } 
  // And if that didn't work, two pixels to the right.
  else {
  cEgo.Move(cEgo.x + 4, cEgo.y, eBlock, eAnywhere);  
  walkies = 1;
  }
} 
// When all is right again, reset the rig.
else if (areanumber != 0) {
  walkies = 1;
}
} 


I dont think it's a pretty way to do it, but heck: it works!
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Khris

Quote from: WHAM on Sun 14/06/2009 21:45:23
Also: It seems that I can only have walkable areas and hotspots in 320x200 resolution (the finer areas of the mask are transformed into "blockier" ones when I import them into the game). However, walk-behind masks dont get the same treatment!?
Is this normal, or am I doing something wrong here?
This is normal. Walkable areas don't need to be pixel prefect, but walkbehinds do as they'd produce graphical errors if their res is smaller than the background's.

The walking off is a bug in the pathfinder, as far as I'm concerned. Might have to do something with the room's width. Try cropping the room to 640 and check if the character still gets stuck.

GuyAwesome

WHAM, that solution is pretty similar to what I was thinking last night, actually. Just couldn't quite figure out HOW to do it at the time. One thing I would've added is an up/down move as well, but if you say it works as-is, I guess it isn't needed...

WHAM

#9
Quote from: GuyAwesome on Mon 15/06/2009 11:24:28
WHAM, that solution is pretty similar to what I was thinking last night, actually. Just couldn't quite figure out HOW to do it at the time. One thing I would've added is an up/down move as well, but if you say it works as-is, I guess it isn't needed...

If the character only ever crosses the border by a pixel or two, and if this only happens near a non-straight 90 degree edge, sideways movement should be adequate.

If anyone has a better solution, I would welcome it! As it is now, it looks like my character gets some kind of seizures every now and then, as the game forces him to move back to a walkable area through trial and error. It also stops the character dead in his tracks, meaning that if the player was being chased: you're dead!
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Vince Twelve

I'm not sure how you would be having this bug with the pathfinder while no one else has this problem.  I have rooms with walkable areas similar to yours and have never seen a similar problem.

However, I had one person email me about having a bug in Linus Bruckman where she would keep getting stuck when the player would walk off a corner.  No matter how hard I tried, I could never reproduce it, but she could send me a save game that had the player stuck off of the walkable areas.  She said it happened to her every time she played, but no one else ever had this problem.  I was never able to help her.

Could there somehow be an issue with the way one computer calculates the path while other computers would calculate it fine?

WHAM, can you upload an example room that has this problem (without your jump back to walkable area fix)? To see if other computers have the same problem while playing?

WHAM

Quote from: Vince Twelve on Mon 15/06/2009 15:26:23
I'm not sure how you would be having this bug with the pathfinder while no one else has this problem.  I have rooms with walkable areas similar to yours and have never seen a similar problem.

However, I had one person email me about having a bug in Linus Bruckman where she would keep getting stuck when the player would walk off a corner.  No matter how hard I tried, I could never reproduce it, but she could send me a save game that had the player stuck off of the walkable areas.  She said it happened to her every time she played, but no one else ever had this problem.  I was never able to help her.

Could there somehow be an issue with the way one computer calculates the path while other computers would calculate it fine?

WHAM, can you upload an example room that has this problem (without your jump back to walkable area fix)? To see if other computers have the same problem while playing?

So far three computers in the hands of three poeple have reproduced the effect. I'll PM you the link to the test room I'm working with, so you can see what's going on for yourself, if you're really interested. I'll get to it some time this evening.

Could the problem be in the fact that the game is in 640x400, with far wider scrolling rooms and there being a scaling effect in the walkable areas? Maybe the scaling causes the characters center point to move that one pixel over the side somehow?
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

WHAM

Okay, this is getting weird.

I just created a second room within the same game, using the same walkable area mask and POOF: The character cannot get stuck anymore. I turned off the script that moves Ego to a walkable area, and still he wont get stuck!
I then created the script that follows what walkable area Ego is on, making him say "Im on zero" when he walks onto the walkable area "0". In "Room 1", he walks to the edge, speaks the line and is stuck in a loop saying the line, due to it being in a repeatedly execute section of the global script.

BUT in "Room 2", which to my understanding is identical to room 1, he speaks the line once and is then returned onto a normal walkable area automatically! I've checked and double-checked. I didn't do this! AGS just seems to function differently in different rooms when it comes to this issue.

NOW: I created a template of "room 2" and used it to replace "room 1" and everything's workin perfectly!
I don't get it! Same mask, same resolution, same values of scaling on each walkable area: EVERYTHING!
On the other hand, a template of "room 1" used as any other room, results in getting stuck just as before.

I am officially dumbfounded!
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

SMF spam blocked by CleanTalk