My character doesn't walk in my second room

Started by nightmarer, Tue 25/02/2020 15:38:29

Previous topic - Next topic

nightmarer

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

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

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.

TheManInBoots

#3
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.

nightmarer

Hello, I replace the background and now it works. I don't know how, but know it works.

Thank you all again.

Regards.

ManicMatt

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

#6
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.

Laura Hunt

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.

Crimson Wizard

#8
Quote from: Laura Hunt on Wed 26/02/2020 14:29:12
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.

ManicMatt

Quote from: TheManInBoots on Wed 26/02/2020 14:13:07
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

#10
Oh yes, I forgot that in that moment.

fernewelten

#11
Quote from: Crimson Wizard on Wed 26/02/2020 16:01:14
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.

Crimson Wizard

#12
Quote from: fernewelten on Wed 26/02/2020 18:28:08
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.

fernewelten

#13
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.

Crimson Wizard

@fernewelten, perhaps it's better to post these ideas in the github ticket, they will be lost here (and they are offtopic).

SMF spam blocked by CleanTalk