• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

need help with tile collisions

G

Guywithabag

Guest
I have a sprite with a collision box that is rectangular shaped but it seems to teleport or push itself downwards then snap to a grid and can sometimes go through walls. Please i need someone to help me

i am using the code in
Tilemap Collisions in GMS 2 - GMWolf

var dx = moveSpeed * (keyboard_check(vk_right) - keyboard_check((vk_left)));
var dy = vsp;
vsp += grav;

//jump
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_up)) {
vsp = -jump_impulse;
}
}
//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 & ~31) - 1) - sprite_bbox_bottom;
vsp = 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 +32) & ~31) - sprite_bbox_top;
vsp = 0;
}
}

//do horizontal move
x += dx;
if (dy > 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 & ~ 31) - 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 + 32) & ~31) - sprite_bbox_left;

}
}
 
Top