GameMaker: Studio

GameMaker: Studio

통계 보기:
Il Boscaiolo 2015년 11월 1일 오후 4시 41분
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.
< >
7개 댓글 중 1-7개 표시
Thew 2015년 11월 1일 오후 4시 43분 
Can you post the code you're having a problem with?
Il Boscaiolo 2015년 11월 1일 오후 4시 51분 
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
Il Boscaiolo 님이 마지막으로 수정; 2015년 11월 1일 오후 4시 53분
DirectOrder 2015년 11월 1일 오후 7시 22분 
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 2015년 11월 2일 오전 2시 30분 
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 2015년 11월 2일 오전 7시 55분 
bump?
Elec 2016년 5월 5일 오전 11시 59분 
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 2016년 5월 6일 오전 7시 14분 
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!
< >
7개 댓글 중 1-7개 표시
페이지당 표시 개수: 1530 50

게시된 날짜: 2015년 11월 1일 오후 4시 41분
게시글: 7