What type of pathing are you planning with? A* or mp_step? Or another?
I'm going to explain this in regards to having many instances with each their own path. This works well with RTS games or click to move games. Fire with Fire is a little different becuase all the units use only 1 of 2 paths but in your game you might have units all over the place then tell them all to goto the same spot. Alright here is how it works. The mpgrid is very important. But no I do not use mp_potential step.
What I like to do is if it exists destroy the grid for each instance east step. Then re-make it. Because I have a very small room in fire with fire I make the grid for the entire room. But the real reason I remake the grid every step is in cases where you have a large room, in this case your grid should be a fraction.
Make sure the grid snaps to what ever factor your making your sprites and object masks. This pretty much wont work unless your walls are 24x24 or 32x32 or whatever it may be.
if mpgrid > 0{
mp_grid_destroy(global.mpgrid);}
mpgrid = mp_grid_create(0,0,room_width/24,room_height/24,24,24);
Next we add in our walls and other objects. Now in Fire with Fire its okay for the creeps to cross over each other but say in your game you want your units to bump into each other. First line adds all wall instances second line on, effects your units. This checks other unit_obj instances mpgrid and if they arent within 48px of the current instance then they are just ignored.
mp_grid_add_instances(global.mpgrid,wall,0);
with unit_obj{
if id != other.id{
dis = scr_dis(floor(x/24)*24,floor(y/24)*24,floor(other.x/24)*24,floor(other.y/24)*24);
if dis <= 48{mp_grid_add_instances(other.mpgrid,id,0);}
}}
Notice when we assign x, y,other.x, other.y in scr_dis what we are doing is making those variable snap to the grid by the 24x24 factor. here is scr_dis for you guys, This is just a normal distance between to points script.
value = sqrt(sqr(argument0-argument2)+sqr(argument1-argument3));
return value;
Now that we have our grid. Lets grid the path. use pathtop = path_add(); in the creation event, this one were just going to clear every step and re grid it. and were snapping the startx, y just like in scr_dis we need to do this for the goalx,y also. This ensures the path lines up with the mpgrid and makes this whole thing reliable.
path_clear_points(pathtop);
startx = floor(x/24)*24;
starty = floor(y/24)*24;
mp_grid_path(mpgrid,pathtop,startx,starty,goalx,goaly,1);
Now everything is setup, and a path is generated every step. what we do instead of mp_potential_step() or path_start() and this is a million times better and faster is simply get the direction of the instance when its going along its path, and then simply tell it to move in that direction.
direction = point_direction(path_get_point_x(pathtop,0),path_get_point_y(pathtop,0),path_get_point_x(pathtop,1),path_get_point_y(pathtop,1));
move_contact_solid(direction,1);
Edited by StallionTG, 26 July 2012 - 03:19 AM.