Jibble

Author Topic: My character doesn't walk in my second room  (Read 277 times)

My character doesn't walk in my second room
« on: 25 Feb 2020, 15:38 »
Hello.

I've been some days with this problem. I created my second room and my character can't walk on it, but he can interact with a hotspot.
The walkable area is created and the character appears on this walkeble areaso I don't know what I have to do.
Here I paste the script to change the room:
From room1 to room 2:
function room_LeaveRight()
{
cChar1.ChangeRoom(2, 99, 455, eDirectionRight);
}

function room_LeaveLeft()
{
cChar1.ChangeRoom(2, 500, 455, eDirectionLeft);
}

From room 2 to room 1:
function room_LeaveLeft()
{
cChar1.ChangeRoom(1, 753, 509);
//cChar1.ChangeRoom(1, 753, 509, eDirectionDownLeft);
}
function room_LeaveRight()
{
cChar1.ChangeRoom(1, 504, 531, eDirectionLeft);
}

Do I need to activate anything else?

Regards.

Slasher

  • slasher
    • I can help with AGS tutoring
    • Lifetime Achievement Award Winner
    • I can help with scripting
    • I can help with story design
    • Slasher worked on one or more games that won an AGS Award!
    •  
    • Slasher worked on one or more games that was nominated for an AGS Award!
Re: My character doesn't walk in my second room
« Reply #1 on: 25 Feb 2020, 16:33 »
Check where your edges are for a start... and did you use the room's edges properties and not just copied and pasted?

Does the player actually land on a walkable area and not off it?

Food for thought..




Khris

  • partook in silencing a crtitc despite facts
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on one or more games that was nominated for an AGS Award!
Re: My character doesn't walk in my second room
« Reply #2 on: 25 Feb 2020, 17:50 »
You can check the reachable walkable areas during the game by pressing Ctrl+A (if debug mode is enabled).
Make sure they appear and you didn't accidentally draw regions or walk behinds.
Fail at Floaty Rog' now!  still having to deal with what games are going through

TheManInBoots

  • Epically wrote function to declare an int
Re: My character doesn't walk in my second room
« Reply #3 on: 25 Feb 2020, 21:20 »
Normally you shouldn't have to activate anything else.
Most likely your character is not really on the walkable area.

When your character has an offset, so when the character is not really on the bottom of the sprite, it can happen that it looks like the character stands on the walkable area, whereas in fact he stands below.

So that's the first thing I would check.
The easiest way for you to check that is to go to the Room Editor for room 2 and move the mouse to the positions 99, 455 and 500, 455 (the mouse position is indicated in the left top corner of the editor). And if at that spot where the mouse is you have a walkable area, then you know the walkable area is correct. If not, you found the problem.
« Last Edit: 25 Feb 2020, 21:23 by TheManInBoots »

Re: My character doesn't walk in my second room
« Reply #4 on: 25 Feb 2020, 21:22 »
Hello, I replace the background and now it works. I don't know how, but know it works.

Thank you all again.

Regards.

Re: My character doesn't walk in my second room
« Reply #5 on: 25 Feb 2020, 23:30 »
Hmm, it's a shame you don't know what went wrong. If a similar issue happens again, you didn't learn from your previous mistake. :/

TheManInBoots

  • Epically wrote function to declare an int
Re: My character doesn't walk in my second room
« Reply #6 on: 26 Feb 2020, 14:13 »
If nightmarer changed the background, he had to redraw the walkable areas.
Also he might have actually changed it to a different background where the walkable areas lay in a different place.
Either way he had to redraw the walkable areas, and now the character coordinates lay on the walkable area and the character walks.
That's the only explanation.
The character just looked as if he was standing on the walkable area, or nightmarer had actually drawn walk behinds the first time.

Maybe nightmarer, you would like to share a sprite of the character, just to see if there's a big offset (a big gap) on the bottom of the sprite?
In this case it might have been that the character didn't actually stand on the walkable area.
« Last Edit: 26 Feb 2020, 14:17 by TheManInBoots »

Re: My character doesn't walk in my second room
« Reply #7 on: 26 Feb 2020, 14:29 »
Nobody has mentioned this yet, but a useful command to know is Character.PlaceOnWalkableArea(), which ensures that your character is indeed on a walkable area.

Re: My character doesn't walk in my second room
« Reply #8 on: 26 Feb 2020, 16:01 »
Nobody has mentioned this yet, but a useful command to know is Character.PlaceOnWalkableArea(), which ensures that your character is indeed on a walkable area.

I will take this chance to mention that it has a flaw and does not work in 100% case :): https://github.com/adventuregamestudio/ags/issues/163

In short, it checks only each 4th or 5th pixel on the mask, and if your area is thinner, then it may miss it.
« Last Edit: 26 Feb 2020, 16:03 by Crimson Wizard »

Re: My character doesn't walk in my second room
« Reply #9 on: 26 Feb 2020, 17:11 »
If nightmarer changed the background, he had to redraw the walkable areas.

Only if the size of the background was different. If it was the same dimensions then the walkable areas would remain intact.

TheManInBoots

  • Epically wrote function to declare an int
Re: My character doesn't walk in my second room
« Reply #10 on: 26 Feb 2020, 17:15 »
Oh yes, I forgot that in that moment.
« Last Edit: 26 Feb 2020, 18:16 by TheManInBoots »

Re: My character doesn't walk in my second room
« Reply #11 on: 26 Feb 2020, 18:28 »
Character.PlaceOnWalkableArea() [...] checks only each 4th or 5th pixel on the mask, and if your area is thinner, then it may miss it.

Nowadays, memory is essentially unlimited. So one way of fixing that would be to precompile for each point of the 5x5 grid and each walkable area where the nearest area point is, but only if this point is within +3 pixels in x or y direction. This would only need to run in the Editor when the area has changed and is saved and only on the grid points that are affected. If packed optimally, this would need 1 byte per grid point per active area (since two values from -3 to +3 fit into 1 byte).

At runtime, the algorithm for Character.PlaceOnWalkableArea() could work exactly as before,  but on each point of the 5x5 grid it checks whether an active area is near (using the precompiled list) instead whether an active area is right on the grid point. This can never garner a worse result than only checking the exact point of the 5x5 grid. Specifically, when a grid point is right on an active area, the new algo will give exactly the same result as the old algo.

For each point of the grid, there are at most n checks to find the nearest active area using the precompiled list, where n is the number of active areas of the room, so runtime wise this calculation isn't too bad.

There are still some snags and details to iron out  in order to make this work in practice, but the gist of the algo should work.
« Last Edit: 26 Feb 2020, 18:40 by fernewelten »

Re: My character doesn't walk in my second room
« Reply #12 on: 26 Feb 2020, 18:37 »
Nowadays, memory is essentially unlimited. So one way of fixing that would be to precompile for each point of the 5x5 grid and each walkable area where the nearest area point is, but only if this point is within +3 pixels in x or y direction. This would only need to run in the Editor when the area has changed and is saved and only on the grid points that are affected.

I have to mention, recently added to the master branch, there's now a method to change area masks at runtime.
https://github.com/adventuregamestudio/ags/pull/1031

I wonder though, if the navigation grid created for the new A* pathfinder could be reused for PlaceOnWalkableArea.
« Last Edit: 26 Feb 2020, 18:40 by Crimson Wizard »

Re: My character doesn't walk in my second room
« Reply #13 on: 26 Feb 2020, 23:16 »
An even simpler way: For each 5x5 grid point and each walkable area, only remember _whether_ that area has at least one pixel within x + 3, y + 3 around the grid point. This information is fairly easy to keep up-to-date, even when areas are changed at runtime. And it can be stored compactly.

When Character.PlaceOnWalkableArea() is called, find the point on the 5x5 grid that is nearest to the character and from there, do a breadth-first search for the first grid point that has an active area nearby, using the precompiled information. Then from that grid point, do a pixelwise breadth-first search to find the specific nearby pixel that belongs to that area. Move the character to that pixel.
« Last Edit: 26 Feb 2020, 23:22 by fernewelten »

Re: My character doesn't walk in my second room
« Reply #14 on: 26 Feb 2020, 23:37 »
@fernewelten, perhaps it's better to post these ideas in the github ticket, they will be lost here (and they are offtopic).