Smaller tile for collision

Im bad at coding and cant figure out how to make a smaller tile for more versatile use
Create
Code:
move_speed = 4;
jump_impulse = 15;
grav = .75;
v_speed = 0;

//Tile map info
var l = layer_get_id("collision_map");
tilemap = layer_tilemap_get_id(l);
Step
Code:
//sprite info
sprite_bbox_left = sprite_get_bbox_left(sprite_index) - sprite_get_xoffset(sprite_index)
sprite_bbox_right = sprite_get_bbox_right(sprite_index) - sprite_get_xoffset(sprite_index)
sprite_bbox_bottom = sprite_get_bbox_bottom(sprite_index) - sprite_get_yoffset(sprite_index)
sprite_bbox_top = sprite_get_bbox_top(sprite_index) - sprite_get_yoffset(sprite_index)




/// 0description Insert description here
var t1 = tilemap_get_at_pixel(tilemap, bbox_left, bbox_bottom + 1) & tile_index_mask;
var t2 = tilemap_get_at_pixel(tilemap, bbox_right, bbox_bottom + 1) & tile_index_mask;
if (t1 != 0 || t2 != 0)
    if keyboard_check(vk_space)
    v_speed = -jump_impulse
    


var dx = move_speed * (keyboard_check(vk_right) - keyboard_check((vk_left)));
keyAttack = keyboard_check_pressed(ord("Z"));
var dy = v_speed;
v_speed += grav;

//do vertical move
y += dy;
if ( dy > 0 )  { //downwards
    var t1 = tilemap_get_at_pixel (tilemap, bbox_left, bbox_bottom) & tile_index_mask;
     var t2 = tilemap_get_at_pixel(tilemap, bbox_right, bbox_bottom) & tile_index_mask;
    
     if(t1 != 0 || t2 != 0) {
        y = ((bbox_bottom & ~63) - 1) - sprite_bbox_bottom;
        v_speed = 0;
     }
} else { //upwards
    var t1 = tilemap_get_at_pixel (tilemap, bbox_left, bbox_top) & tile_index_mask;
     var t2 = tilemap_get_at_pixel(tilemap, bbox_right, bbox_top) & tile_index_mask;
    
     if(t1 != 0 || t2 != 0) {
        y = ((bbox_top + 64 ) & ~63) - sprite_bbox_top;
        v_speed = 0;
     }
}

//do horizontal move
x += dx;
if ( dx > 0 )  { //right
    var t1 = tilemap_get_at_pixel (tilemap, bbox_right, bbox_top) & tile_index_mask;
     var t2 = tilemap_get_at_pixel(tilemap, bbox_right, bbox_bottom) & tile_index_mask;
    
     if(t1 != 0 || t2 != 0) {
        x = ((bbox_right & ~63) - 1) - sprite_bbox_right;
     }
} else { //left
    var t1 = tilemap_get_at_pixel (tilemap, bbox_left, bbox_top) & tile_index_mask;
     var t2 = tilemap_get_at_pixel(tilemap, bbox_left, bbox_bottom) & tile_index_mask;
    
     if(t1 != 0 || t2 != 0) {
        x  = ((bbox_left + 64 ) & ~63) - sprite_bbox_left;
     }
}
I need it to be the size of about 1 normal sized tile
 

TheouAegis

Member
You defined your collision points by the corners of your bounding box; if your bounding box is larger than 1 tile, you need to check more points in between the corners.

If you study the code and learn what it is actually doing, implementing more points will be simple enough.

Technically, the size of the tiles doesn't matter; what matters is that the distances between all the points you check are equal to or less than the size of the smallest tile.
 

curato

Member
Yeah, the collision script for the game I am working on the characters are 64x64 and the tiles are 48x48 so I check the four corners and the middle point in between. It gives me 32x32 coverage which is more than enough to keep me from pushing through a tile that is stuck out by itself.
 
Top