• 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!

Tile collision

S

Squirtle Plays

Guest
Hi so when I use this code when I touch wall on the left it teleports my character to where he started in the room any ideas

Code:
/// 0description Insert description here
var dx = move_speed * (keyboard_check(vk_right) - keyboard_check((vk_left)));
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_top + 64 ) & ~63) - sprite_bbox_left;
     }
}
 
Last edited by a moderator:
I

immortalx

Guest
Looks like in the last line you should change bbox_top to bbox_left
 
Top