Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Im new when it comes to custom A* Pathfinding. How do i get an object to follow the created path/array ?

when i add path_start(path,3,0,0) it says ""path_start argument 1 incorrect type (array) expecting a Number""

(1 edit)

do it like this (make sure you delete path when done with it): 

var path_array = ap_grid_path_array(obj_tester.grid, x, y, mouse_x, mouse_y);

path = path_add();

for(var i = 0; i < array_length(path_array); i++){

var point = path_array[i];

path_add_point(path, point[0], point[1], 1);

}

path_start(path, 3, path_action_stop, 0);

With help from the gamemaker discord they came up with this,
Global left click is the same as the demo file, on the Global right click i added follow_path = true

if follow_path = true{

var points_array = path

if array_length(points_array) = 0{

  speed = 0}

else{

  if point_distance(x,y,points_array[0,0], points_array[0,1]) > walk_speed{

    move_towards_point(points_array[0,0],points_array[0,1], walk_speed)  }

  else{

    x = points_array[0,0]

    y = points_array[0,1]

    array_shift(points_array)  }

 }

}

This works really well!