0

Here's my collision code. (I got it from FriendlyCosmonaut but added the debug message for my own benefit):

// COLLISION CHECK
//Horizontal

if (place_meeting(x+moveX,y,obj_solid)){
    repeat(abs(moveX)){
        if(!place\_meeting(x+sign(moveX),y,obj\_solid)){
            x = x + sign(moveX);
        } else {
            break;
        }
    }
    moveX = 0;
    show_debug_message("collision");
}

//Vertical
if (place_meeting(x,y+moveY,obj_solid)){
    repeat(abs(moveY)){
        if(!place\_meeting(x,y+sign(moveY),obj\_solid)) {
            y = y + sign(moveY);
        } else {
            break;
        }
    }
    moveY = 0;
    show_debug_message("collision");
}

see pic, red border is part of sprite for clarity

enter image description here

game is allowing a 32px overlap before actually setting moveY to 0; the collision mask starts 16px down from the top of the sprite. (origin is set to top left, which is outside the collision mask range.) it then "traps" me there, and i cannot move in any direction. and the debug output registers like 100 "collision"s...

based on yoyo's documentation I thought place_meeting was for mutual precise masks only, which admittedly I've not using here, but the code won't work even if I do (though would probably give different coordinates and output--I didn't check all scenarios).

I really have no clue why this is broken and have tried other codes to the same effect. this is what I've selected as a troubleshooting starting point, and I appreciate any help I can get! please don't come for me bc i didn't provide every necessary detail or fkd something up. I'm a novice, and I'm here to learn. :)

Update: Apparently the collision does happen with other types of collision masks (precise and diamond for instance). But that does not create the look I want--it really needs to be a manual rectangle.

SSK
  • 3,444
  • 6
  • 32
  • 59
  • It's probably not relevant, but why are there `\ ` inbetween the `place_meeting` and `obj_solid`? I'm not sure if that was intentional – Steven Feb 19 '21 at 07:48
  • For the question itself, I think this has to do with the origin point itself, because it's set at top-left, and outside of the collision box. – Steven Feb 19 '21 at 07:52

1 Answers1

1

you need to replace the repeat with a while.

    if (place_meeting(x+moveX,y,obj_solid)){
      while(!place_meeting(x+sign(moveX),y,obj_solid)){
         x = x + sign(moveX);
      }
      moveX = 0;
    }
    x += moveX;

same for the vertical collision, this scheme should be more clean and immediate.

Sansonight
  • 61
  • 2