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
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.
o_game create
o_player step (the blue pillar)
GML:
GAME_GRID = mp_grid_create(0, 0, room_width, room_height, hcells, vcells);
mp_grid_add_instances(GAME_GRID, o_solid, true);
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);
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
-
8.9 KB Views: 0