Error on Handle Collisions in Corners - Gamemaker Studio

108 Views Asked by At

When I move my character into the walls, the bottom wall and right wall collisions works fine.

Collision walls that work fine

1 The problem is with the other two walls (the left and top ones), when I'm in collision with'em, my character either drop down or left instantly. I'm not sure with it happens. Here's the code directly from my project:

function CollisionHandle() {
    var _pixel1, _pixel2;
    //Commit to h movement
    x += hspd;
    
    // H tile collition
    if (hspd > 0)
    {
        _pixel1 = tilemap_get_at_pixel(collisionMap, bbox_right, bbox_top) & tile_index_mask;
        _pixel2 = tilemap_get_at_pixel(collisionMap, bbox_right, bbox_bottom) & tile_index_mask;
        if (_pixel1 != 0 || _pixel2 != 0)
        {
            x = ((bbox_right & ~(TILE_SIZE-1)) - 1) - bboxRightPortion;
        }
    }
    else
    {
        _pixel1 = tilemap_get_at_pixel(collisionMap, bbox_left, bbox_top) & tile_index_mask;
        _pixel2 = tilemap_get_at_pixel(collisionMap, bbox_left, bbox_bottom) & tile_index_mask;
        if (_pixel1 != 0 || _pixel2 != 0)
        {
            x = ((bbox_left + TILE_SIZE) & ~(TILE_SIZE-1)) - bboxLeftPortion;
        }
    }
    
    //Commit to v movement
    y += vspd;
    
    // V tile collition
    if (vspd > 0)
    {
        _pixel1 = tilemap_get_at_pixel(collisionMap, bbox_right, bbox_bottom) & tile_index_mask;
        _pixel2 = tilemap_get_at_pixel(collisionMap, bbox_left, bbox_bottom) & tile_index_mask;
        if (_pixel1 != 0 || _pixel2 != 0)
        {
            y = ((bbox_bottom & ~(TILE_SIZE-1)) - 1) - bboxBottomPortion;

        }
    }
    else
    {
        _pixel1 = tilemap_get_at_pixel(collisionMap, bbox_right, bbox_top) & tile_index_mask;
        _pixel2 = tilemap_get_at_pixel(collisionMap, bbox_left, bbox_top) & tile_index_mask;
        if (_pixel1 != 0 || _pixel2 != 0)
        {
            y = ((bbox_top + TILE_SIZE) & ~(TILE_SIZE-1)) - bboxTopPortion;

        }
    }
}

And here's the video which I followed the instructions: (https://youtu.be/ysGM5dibzu8?t=1218) In the video, the collisions work fine for him and I verify all my project to try to spot some bad typing word or something else. Btw, I'm learning GML so that's why I can't really figure out what's going on :,3. I could really type wrong some variable so either way any help would be helpful for me :D!

1

There are 1 best solutions below

0
On

I think this may have to do with the origin point, as that's by default set to top-left. Seeing you're comparing x and y positions with collissions, you rather want it to be at the center.