• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Pathfinding with grid's shifted, Filling the grid

mafon2

Member
I followed two of the most popular tutorials about pathfinding and got the amazing results I've been trying (with horrible results) to write algorithms for. Didn't know there's already built in stuff. But for some reason the grid instances appear shifted 16p down and 16p right, plus sometimes the skeleton is smashing into the walls. I think it's something to do with the sprite origins, 'cause when I center it, the skeletons move better (yet still too "fluidly" for my taste and blurry for some reason).



The code on the skeleton is:

Code:
path = path_add();
mp_grid_path(global.grid,path,x,y,obj_digger.x,obj_digger.y,0);
path_start(path,2,"",0);
moveTimer = global.cell_size;
(Don't know if moveTimer does anything... added it for more "square" movement)

The code for grid is:
Code:
global.grid = mp_grid_create(0,0, room_width div 32, room_height div 32, 32, 32);
mp_grid_add_instances(global.grid, obj_block, false);
Is it like I need to add "+16" part to mp_grid_create?

My sprites' origins are set to default 0,0 and grid's drawn from 0,0. I don't get why's it shifted. And that's the question :). BTW, would be gratefull to get the answer to how to make monsters move like in old arcade games "crisp pac man style".

P.S. And with the simplest: [mp_potential_step(obj_digger.x,obj_digger.y,2,true);] monsters have troubles squizing through minimal 32p gap.

P.P.S. Making my Digger Game.

-------------------------------

Oh, and while we're at it.

How to fill this global.grid with instances? (So I don't place every dirt block manualy)
 
Last edited:
F

Facet

Guest
I not read whole question, but from first sentence I can ask you for check origin point in your objects. Here default is 0,0 and it can looks shifted, with 32 pixels objects for example and maybe you have to set origin in 50% width 50% height of sprite/object as I think.
 
A

anomalous

Guest
1. To draw crisp (pixel-perfect), you need to draw on integer coordinates. You can round the x/y value before drawing, and it should draw crisp. You can get the opposite effect, jittery (yet crisp looking pixels!) movement, but this is all just how it is. Things can minimize this (size of the shapes, movement speed, etc.), but its part of style/design.

2. mp grid is to the center of the grid. Check out the manual I think it details that? You want the origin of the sprite probably at the sprite center for anything moving around on that grid.
Basically where you want them to be "centered" on the ground. For some perspective that may be between the feet, but in your case it looks drawn side view, but calculated on top-view, so center should be fine.

3. mp potential - you may find that using a circular collision mask, slightly smaller than your grid size, will help. Corners are hard to get around yo ;)

For a digger game, you may not need/want to use mp potential, not sure why you would use that for this style game, instead of just following the path..are you wanting them to avoid each other?
You may find you can code something that looks better than mp_potential but still meets your needs, that could be a different thread that you clearly describe what you have, and what you want, as far as movement goes, although a lot of threads in the past few months address this.
 

mafon2

Member
2. Thank you, I just imagined that the path is set with the cells and not along the grid, hence the confusion.

3. mp potential – I'm planning to use it when there's no path to obj_digger so skeleton do show some activity (though it seems like highly improbable situation...), plus the big gaps of "jumps" provide very interesting jaggy movement, suitable for a "random" enemy (maybe). Each ghost in Pac Man had its own pattern of movement, as I recall, and I want to have differently behaving skeletons too.

P.S. My level of codding is very crude, it's mostly different kinds of " if place meets then". So I find a great relief in box solutions.

--------

And to answer my own question about filling:

Code:
repeat (room_height div 32)
{
if (place_empty(x,y))
{
instance_create(x,y, obj_dirt)
}
y+=32
}
Plus same thing, but which would copy the vertical lines generator horizontally.
 
Last edited:
Top