PlaceOnWalkableArea doesn't work all the time

Started by dayowlron, Mon 15/01/2018 17:18:30

Previous topic - Next topic

dayowlron

I will have several doors in my game so I created a function that I will call that will open and close my doors. Later when I get to adding sound I will put that in the one spot and will work for all my doors. All of my doors have a 5 image(frames numbered 0-4) animation for opening and closing. When a room loads I set the view for the door and then when the player wants to open or close the door I just call the function. When the door is open there is another walkable area that is enabled that allows them to go through the door. It is disabled when the player closes the door. This is where the problem occurs.
Code: ags


static function OpenDoor(Object*obj, int WalkableAreaToEnable) {
  if (obj.Frame==0) {
    obj.Animate(obj.Loop, 5, eOnce, eNoBlock, eForwards);
    if (WalkableAreaToEnable!=0) RestoreWalkableArea(WalkableAreaToEnable);
  }
}

static function CloseDoor(Object*obj, int WalkableAreaToDisable) {
  if (obj.Frame==4) {
    obj.Animate(obj.Loop, 5, eOnce, eNoBlock, eBackwards);
    if (WalkableAreaToDisable!=0) RemoveWalkableArea(WalkableAreaToDisable);
    player.PlaceOnWalkableArea();
  }
}


My problem is when the walkable area is removed and then i call player.PlaceOnWalkableArea sometimes it works sometimes it doesn't.
I have walkable area #1 always available so its not like it can't find a walkable area.

EDIT: I have even tried putting the player.PlaceOnWalkableArea() call in the repeatedly_execute function and verified that it is being called.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Crimson Wizard

IDk if related, but I made a bug ticket about this a while ago, but did not do any research since this was never reported by actual game developer.
https://github.com/adventuregamestudio/ags/issues/163

dayowlron

I bet it is related and I am not sure why it happens, but in most of my rooms it works fine but this one particular room is a hallway with 5 doors so there is multiple walkable areas. 1 is the hallway itself and 2-6 are entryways through each of the doors. this is the first room of my game with multiple doors so don't know if its related to that.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Crimson Wizard

Could you upload your room, or at least walkable area mask image?

dayowlron

ok, this may sound like a strange question, but is there a site where i can upload it and then provide the link in here?
How do I upload a room on here?
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Crimson Wizard

Use any hosting service, Dropbox, Mediafire, google drive, etc, etc.

dayowlron

Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Crimson Wizard

#7
Dammit!

There is a NON-DOCUMENTED exception to PlaceOnWalkableArea, which I found only by reading the engine code. Character will not be moved, if walkable area is beyond the room Edges.

Yours main walkable area in that room is exactly below the "bottom edge".

Solution: adjust the room's edges.

(E: On further thinking, that kind of makes sense, since edges usually define exit zones. There's still an issue however, that PlaceOnWalkableArea is secretly used in some engine functions related to walking/moving character, which may cause trouble. Perhaps adding special mode to "ignore edges" may be a good idea)

E2: Another possible reason why PlaceOnWalkableArea may not work: it does not check every pixel of the walkable area mask, but makes checks with 5 pixel interval. Which means that if your walkable area is 1 to 4 pixels thick there is a chance it will be missed.

dayowlron

#8
OK, thanks for clearing that up. I will do that tonight and try it out. I usually don't mess with the edges unless I am going to have events for walking off edges.

EDIT: That seems to have been the problem. It is all working now.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

SMF spam blocked by CleanTalk