game-makergmlgame-maker-languagegame-maker-studio-2

I'm having trouble getting bbox based gml collisions to work. My horizontal one is fine. Its just my vertical


So initially I set the bbox and sprite_index stuff (I know you should use the mask but I'm not up to animations yet so I'm keeping it simple for now).

var sprite_bbox_top = sprite_get_bbox_top(sprite_index) - sprite_get_yoffset(sprite_index);
var sprite_bbox_right = sprite_get_bbox_right(sprite_index) - sprite_get_xoffset(sprite_index);
var sprite_bbox_left = sprite_get_bbox_left(sprite_index) - sprite_get_xoffset(sprite_index);
var sprite_bbox_bottom = sprite_get_bbox_bottom(sprite_index) - sprite_get_yoffset(sprite_index);

So below is the hsp code. This is working just fine.

   if (place_meeting(x + hsp, y, argument0)) {
        while (!place_meeting(x + sign(hsp), y, argument0)) {
            x += sign(hsp);
        }
        _wall = instance_place(x + sign(hsp), y, argument0);
        if (hsp > 0) {
            x = (_wall.bbox_left - 1) - sprite_bbox_right;
        }
        else {
            x = (_wall.bbox_right + 1) - sprite_bbox_left;
        }
        hsp = 0;
    }

Here is the code that isn't working. As you can see this is the same but for y. I don't understand how it can be reacting differently. When I go down and collide with argument0 the object moves quickly to the right (pos x). When I go upwards and collide it disappears altogether.

if (place_meeting(x, y + vsp, argument0)) {
    while (!place_meeting(x, y + sign(vsp), argument0)) {
        y += sign(vsp);
    }
    _wall = instance_place(x, y + sign(vsp), argument0);
    if (vsp > 0) {
        y = (_wall.bbox_bottom - 1) - sprite_bbox_top;
    }
    else {
        y = (_wall.bbox_top + 1) - sprite_bbox_bottom;
    } 
    vsp = 0;
}

Solution

  • It can be one of two things:

    1. the speed is not compatible with the displacement for example if it moves to two pixels and has a speed of three when there is a colicion it will stop moving because it will be out of square, I hope that you achieve this, it happened to me many times before discovering that it was the speed

    2. the anchor point or point of origin may be moved, check the sprite and make sure that where it says origin is 0.0 by default or what is the same left upper, sometimes we move by mistake and without realizing for the moment I can only think of those two because I see no error in the code which means that the error is in another section or another side

    if it helps you in something my answer give me a +1 XD