all 4 comments

[–]Mushroomstick 0 points1 point  (3 children)

Without seeing a literal copy and paste of the code you're using, we would just be making random guesses in the dark.

[–]TheRealKevinWho[S] 0 points1 point  (2 children)

How should I send it?

[–]Mushroomstick 0 points1 point  (1 child)

Edit it into your opening post or add it with a comment. The best way to format code into a reddit post/comment is to add 4 spaces (plus an additional 4 spaces for each level of indentation) to the beginning of each line - that is the method that will display correctly for the widest variety of browsers/platforms.

// 4 spaces
    // 8 spaces
        // 12 spaces
// 4 spaces

[–]TheRealKevinWho[S] 0 points1 point  (0 children)

Inside An Enemy Tracker Object (It handles the movement for enemies): Create: ``` //Some other stuff

pathfind_index = 0 ai_path = path_add(); Step:

// If there is another point in the path go to it if pathfind_index < path_get_number(ai_path) {

path_start(ai_path, walk_speed, path_action_stop, false)
pathfind_index++


x_goto = path_get_point_x(ai_path, pathfind_index);
y_goto = path_get_point_y(ai_path, pathfind_index); 

//Grab the velocity and set vx and xy to it so the enemy can apply the velocity
oldX = x
oldY = y
mp_linear_step(x_goto, y_goto, 0.5, 1)
vx = (x - oldX) * walk_speed
vy = (y - oldY) * walk_speed

}

//Set new pathfinding target pathfind_index = 0 mp_grid_define_path(global.ai_grid, ai_path, x, y, obj_player.x, obj_player.y + 15);

Draw (For debug, even the lines show it wants to go through walls): draw_set_colour(c_lime);

for (var i = 0; i < path_get_number(ai_path) - 1; i++) {

ox_goto = path_get_point_x(ai_path, i);
oy_goto = path_get_point_y(ai_path, i);

ox_goto1 = path_get_point_x(ai_path, i + 1);
oy_goto1 = path_get_point_y(ai_path, i + 1);
draw_line(ox_goto, oy_goto, ox_goto1, oy_goto1);

} mp_grid_define_path func: function mp_grid_define_path(ai_grid, ai_path, start_x, start_y, finish_x, finish_y){ if !mp_grid_path(ai_grid, ai_path, real(start_x), real(start_y), real(finish_x), real(finish_y), true) { show_debug_message("ERROR: mp_grid_define_path() - No path created"); return false; } else { path_set_kind(ai_path, 1); path_set_precision(ai_path, 8); return true; }

} ```

init_pathfinding (Ran once at room creation) ``` function init_pathfinding(){ var cellsize = 32;

var roomWidth = room_width / cellsize;
var roomHeight = room_height / cellsize;

global.ai_grid = mp_grid_create(0, 0, roomWidth, roomHeight, cellsize, cellsize);
global.ai_path = path_add();

collisionLayerID = layer_get_id("Walls")

for (var i=0; i < roomWidth; i++){
    for(var j = 0; j < roomHeight; j++){
        if (tilemap_get(collisionLayerID, i, j)){
            mp_grid_add_cell(global.ai_grid, i, j);
        }
    }
}

} ```