1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Smaller tile for collision

Discussion in 'Programming' started by Squirtle Plays, Oct 14, 2019.

Tags:
  1. Squirtle Plays

    Squirtle Plays Member

    Joined:
    Mar 17, 2019
    Posts:
    47
    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
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,143
    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.
     
  3. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    424
    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.
     
  4. Squirtle Plays

    Squirtle Plays Member

    Joined:
    Mar 17, 2019
    Posts:
    47
    I'm sorry for inconveniencing you I figured it out I just had to change the tile set format
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice