Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
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
//-------------------------------------------------------------------
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);
}
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
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;