GameMaker: Studio

GameMaker: Studio

View Stats:
Pathfinding issue
So I basically tried any piece of code I found on the internet(forums, tutorials) to make my enemies follow a path to the obj_player but they simply won't move from their place. Tried also to start a new project to see if it was bound to some kind of parent group conflict, but no, it doesn't work on the new project either.
< >
Showing 1-7 of 7 comments
Thew Nov 1, 2015 @ 4:43pm 
Can you post the code you're having a problem with?
Il Boscaiolo Nov 1, 2015 @ 4:51pm 
So I both created a grid_object not to have memory leaks with a
Create event:


var cell_width = 32;
var cell_height = 32;

var hcells = room_width div cell_width;
var vcells = room_height div cell_height;

global.grid = mp_grid_create (0,0, hcells, vcells, cell_width, cell_height);
path = path_add();

// collisions

mp_grid_add_instances (global.grid, obj_wall, false);
_______
and an end game event to destroy the grid
mp_grid_destroy(global.grid);

then in my obj_enemy i have the followings
Create ev:

/// Initialize enemy

image_speed = .2;
spd = 5

///Create the path
path = path_add();

Step ev:

if (mp_grid_path(global.grid, path,x,y, obj_player.x, obj_player.y, 1)) {
path_start(path,4,path_action_stop, false);
}

I also set the obj_grid to be initialized first in my room
Last edited by Il Boscaiolo; Nov 1, 2015 @ 4:53pm
Denigrate Nov 1, 2015 @ 7:22pm 
The A* pathfinding can be a b1tch. I struggled with it for a while. This is code directly from my project. It's in one controler that sets the path for every enemy, rather than having each enemy handle creating the path. I Try it out.

//-------------------------------------------------------------------

globalvar grid;

grid = mp_grid_create(32,32,MAX_X/32,MAX_Y/32,32,32);
mp_grid_add_instances(grid,parent_impassable,1);

with (parent_enemy) { //for every enemy on-screen

path = path_add();
mp_grid_path(grid, path, x, y, obj_player.x, obj_player.y, 1)
path_start(path, movement_speed, "", 1);
}
Il Boscaiolo Nov 2, 2015 @ 2:30am 
tried it(I copypasta'd the code in my obj_grid controller), but still, my enemies don't move. They move only if I use this code

phy_position_x += sign(obj_player.x - x)*spd;
phy_position_y += sign(obj_player.y - y)*spd;

to make them move in a straight line, but ofc they get stuck in walls, since it's not pathfinding.

I don't really know what to do
Il Boscaiolo Nov 2, 2015 @ 7:55am 
bump?
Elec May 5, 2016 @ 11:59am 
If you still haven't fixed it or if anyone else views this topic, if you have a Physics enables room you'll need something like this to get your movement going.


var path_x = path_get_x(path, pos);
var path_y = path_get_y(path, pos);
var pdir = point_direction(phy_position_x, phy_position_y, path_x, path_y);
var vx = lengthdir_x(force, pdir);
var vy = lengthdir_y(force, pdir);
var distance = point_distance(phy_position_x, phy_position_y, path_x, path_y)
phy_speed_x = vx;
phy_speed_y = vy;
Il Boscaiolo May 6, 2016 @ 7:14am 
yes i solved it like long time ago (kinda) but thanks for the help!! i think this code is a little bit different from the one i used, i might try out this one eventually!
< >
Showing 1-7 of 7 comments
Per page: 1530 50

Date Posted: Nov 1, 2015 @ 4:41pm
Posts: 7