[GameMaker/GML] A* pathing issue (mp_grid)

Started by
0 comments, last by antonymity 9 years, 5 months ago

Hi all -

I hope there are some people here that are familiar with this game engine and its scripting feature. I have also posted a request for assistance on the Game Maker forums, but it seems to be pretty slow over there so I'm branching out here as well. I will update appropriately when things get fixed.

- - - - -

To start, I will say that currently my code 'works', as it will move my character along the path and snap him to the grid at the end of the path. The problem is that when he moves horizontally, he dips down about 16 pixels and then goes back up at the end. The same happens for vertical movement - he dips out to the right 16 pixels and goes back at the end of the path.

My grid is created and the path variable defined in a 'grid controller' object in its Create event:


globalvar grid;
globalvar path;

grid = mp_grid_create(0, 0, (room_width / 32), (room_height / 32), 32, 32);
mp_grid_add_instances(grid, obj_Wall, 1);
path = path_add();

The movement is tied to my character object, on a 'Global Left Released' mouse event:


if mp_grid_path(global.grid, global.path, round(self.x div 32) * 32, round(self.y div 32) * 32, round(mouse_x div 32) * 32, round(mouse_y div 32) * 32, 1)
    {
        path_start(global.path, 16, 0, 1);
    }

My game uses 32x32 sprites and tiles. The character sprite has its origin at (0, 0) because if I put it at the center (16, 16) it becomes visually obvious that it's not lined up to the game grid. But even if I force it to spawn in the middle of a tile, it still moves erratically - actually even more so than with the origin at (0, 0).

One thing I have noticed is that if I change the first two values in the 'mp_grid_create' function from '0, 0' to '-16, '-16', my character no longer dips when he moves. However, this causes collision issues when I add the 'obj_Wall' objects into the grid in the next command. Drawing the grid shows that with the '-16, -16' values set, the wall objects fall into 2 mp_grid grid spaces and thus my character will have spots where he cannot enter a grid because part of it is considered a wall, even though it's actually a floor tile.

Is there anything I can do to get my character to stop dipping when he moves while also keeping my grid in line with my tiles?

Thank you for any assistance,

Antonymity

Advertisement

Well -

Inexplicably, changing those mp_grid_create values to '-16, -16' works today. There isn't any collision issue...

Come to think of it, the reason why may be because I removed the sprite from the invisible wall objects that overlap the wall tiles. Before I started working on hiding unexplored areas of the dungeon map, I had re-used an old sprite for these wall objects (which are flagged invisible so they don't show up in game) so I could visually see where the wall collisions would take place. With these sprites gone, perhaps the bounding boxes of these wall objects are only as wide as the little default circle objects are given when there is no sprite.

There's always a chance that this is not what happened as well. At least, that's how things tend to work with me. Stuff happens. Anyway, I tried to delete my post but I couldn't find any option for that so I've left this comment as an update.

Technology, eh?

Antonymity

This topic is closed to new replies.

Advertisement