• 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 Stop Collision & Overlap

huenix

Member
I had this fixed with making all characters/ai solid (using the solid button in the editor, but now i am reading this is not optimal, and i see why)
how can can i get the AI to stop moving and overlapping from its target.
I don't see anything about this. if two ai are moving toward each other and move at the same moment, they both move and overlap. no longer collide and stop

i know its long code, but wanted to whos it all



function scr_AI_track_nearest()
{
//Set closest Character as Target
target = scr_find_nearest_nth_object(x, y, obj_characters,1,1);
lastx = target.x;
lasty = target.y;

ai_xprevious = x;
ai_yprevious = y;



//Collision
var blocked_by;

if (through_walls) && (over_pits = false) //ONLY walks through walls, NOT over pits
{
blocked_by = obj_pit;
}

if (through_walls = false) && (over_pits) //NOT walks through walls, Only over pits
{
blocked_by = obj_wall;
}

if (through_walls = false) && (over_pits = false) //NOT walks through walls, OR over pits
{
blocked_by = obj_solid;
}

if (through_walls) && (over_pits) //Walks through walls AND over pits
{
blocked_by = noone;
}


//Controls AI moving in a Path towards its Target////////////////////////////////////
//variable "path" must exists
path_end(); //stop current movement!
path_clear_points(path); //clear current path
with(obj_point) instance_destroy(); //clear all displayed points
with(obj_goal) instance_destroy(); //clear all displayed points


grid = mp_grid_create( 0, -2, 30, 30, 32, 32); //create a grid on which we gonna work

mp_grid_add_instances(grid, blocked_by, true); //set all cells on which "obj_solid" is positioned, as not available
ready = mp_grid_path(grid, path, x, y, lastx, lasty, false); //find a way and return is found or not, and copy it to path
//ready = mp_potential_path( path, lastx, lasty, 32, 1, false);
path_set_kind(path, false); //set path to be smooth
//path_shift(path, 0, -1)
mp_grid_destroy(grid); //clear movement grid, to free memory

path_length = path_get_number(path) - 1;

var f = instance_create_depth(path_get_point_x(path, path_length), path_get_point_y(path, path_length), 0, obj_goal); //create "finish" point

var i, dir, o;
// create points on path to target, except last point
for(i=1; i<path_length; i++) {
dir = point_direction
(
path_get_point_x(path, i-1), path_get_point_y(path, i-1),
path_get_point_x(path, i+1), path_get_point_y(path, i+1),
);
o = instance_create_depth(path_get_point_x(path, i),path_get_point_y(path, i), 0, obj_point); // creates the arrows on each point
o.image_angle = dir; //sets arrow sprite angle

}
}

if (limit and i > current_limit) { // if limit is enabled and finish point is unreachable
f.image_single = 1;
// delete points on path that are beyond reach
for(i = current_limit; i<=path_length; i++) {
path_delete_point(path, current_limit+1); // since every time we delete path get's shorter by 1 point, still delete next one
}
}
 
Top