• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

mp_grid_add_instances and bbox issues

yashamatt

Member
Hi, I am trying to make a turn-based top-down game and I was trying to use paths as my main source of movement. In my amateurish ways I have set up a mp_grid for movement and I can get basic collisions working fine however, after setting up
GML:
GAME_GRID = mp_grid_create(0, 0, room_width, room_height, hcells, vcells);
mp_grid_add_instances(GAME_GRID, o_solid, true);
and drawing the grid, I have noticed that the collision area does not line up with the bounding box. below the grey areas are objects and the red is the collision area of the object as determined by my grid, (the bounding box on the sprite is automatically set the same width and height as the sprite on the actual sprite s_solid). As a beginner, I am not really sure what I am doing wrong and would love to be nudged (or catapulted) in the right direction. Also if there is a better auto pathing method I would love to find out.

ert.png
o_game create
Code:
globalvar GAME_GRID;
globalvar CELL_SIZE;

CELL_SIZE = 16;

var hcells = room_width div CELL_SIZE;
var vcells = room_width div CELL_SIZE;

GAME_GRID = mp_grid_create(0, 0, room_width, room_height, hcells, vcells);
mp_grid_add_instances(GAME_GRID, o_solid, true);
o_player step (the blue pillar)
Code:
target_x = (mouse_x div CELL_SIZE) * CELL_SIZE + CELL_SIZE / 2;
target_y = (mouse_y div CELL_SIZE) * CELL_SIZE + CELL_SIZE / 2;

if (mouse_check_button_pressed(mb_right))
{
    if (instance_exists(o_goal)) //Make sure there's only one goal
        instance_destroy(o_goal);
    instance_create_layer(target_x, target_y, layer, o_goal);
    is_moving = true;
}

if (instance_exists(o_goal))
{
    myPath = path_add();
    if (mp_grid_path(GAME_GRID, myPath, x, y, o_goal.x, o_goal.y, true))
    {
        path_start(myPath, 4, path_action_stop, true);
    }   
    if place_meeting(x,y,o_goal) is_moving = false;
}
 

Attachments

The first and second parameter of mp_grid_create() is the number of cells, not the room width and height.

GML:
mp_grid_create(0, 0, hcells, vcells, CELL_SIZE, CELL_SIZE );
is probably what you are after.

EDIT: This should work assuming your sprites are a multiple of the cell size, and they are aligned with the mp_grid.
 

yashamatt

Member
The first and second parameter of mp_grid_create() is the number of cells, not the room width and height.

GML:
mp_grid_create(0, 0, hcells, vcells, CELL_SIZE, CELL_SIZE );
is probably what you are after.

EDIT: This should work assuming your sprites are a multiple of the cell size, and they are aligned with the mp_grid.
thanks this helped alot
 
Top