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

Mask trapping player inside blocks.

I

IamN5

Guest
Hey guys, I have been learning GML quite reasonably considering I'm into this for 1-2 days now.
But I have a problem I didnt manage to resolve myself, so I come here ask for some help xD
This platformer has a little problem:
if you jump in this hole and stay like this:
then when you turn around (like this):
you get stuck into the block and can't move/jump.
What I used to move (Get input won't make a difference here I think):
Code:
/// scr_move_state
// Get input
scr_get_input();
// Check for ground
if (place_meeting(x,y+1,obj_solid) ) {
   vspd = 0;
   airjump = 1;
   // Jumping
   if (jump) {
   vspd = -jspd;
   }
}else {
   // Gravity
   if (vspd < 10) {
   vspd += grav;
   }
   // Control jump
   if (keyboard_check_released(vk_space)and vspd < -4) {
      vspd = -4;
   }
 
   // Check for airjump
   if (airjump > 0) {
     if (jump){
     vspd = -jspd;
     airjump -= 1;
     }
  }
}
// Moving right
if (mright) {
    if (hspd < spd) {
        hspd += fric;
        }else{
        hspd = spd;
 }
}
// Moving left
if (mleft) {
    if (hspd > -spd) {
        hspd -= fric;
        }else{
        hspd = -spd
        }
}
// Check for not moving
if (!mright and !mleft or mright and mleft) {
   if (hspd != 0){
       if (hspd < 0){
           hspd += fric;
       }else{
           hspd -= fric;
       }
   }
}

// Horizontal Collisions
if (place_meeting(x+hspd,y,obj_solid) ){
   while (!place_meeting(x+sign(hspd),y,obj_solid) ) {
   x += sign(hspd);
   }
   hspd = 0;
}
// Moving Horizontally
x += hspd;


// Vertical Collisions
if (place_meeting(x,y+vspd,obj_solid) ){
   while (!place_meeting(x,y+sign(vspd),obj_solid) ) {
   y += sign(vspd);
   }
   vspd = 0;
}
// Moving Vertically
y += vspd;
// Control sprites
if (yprevious != y) {
   sprite_index = spr_player_jump;
}else{
if (xprevious != x) {
  sprite_index = spr_player;
  image_speed = .2;
 }else {
  sprite_index = spr_player_stand;
  }
}
// Control sprites direction
if (xprevious < x){
   image_xscale = 1;
}else if (xprevious > x) {
   image_xscale = -1;
}
Code:
grav = 1;
spd = 4;
jspd = 12;
vspd = 0;
hspd = 0;
airjump = 1;
fric = 1;
state = scr_move_state;
image_speed = 0;
image_index = 0;
PS.: The arms/sword are not in the mask, and I can't modify it to avoid this glitch or it'll be too small/won't have legs
 
Last edited by a moderator:

TheouAegis

Member
Are you using Game Maker Studio or game maker 8? What is the width of your Sprite? What is the bounding box setup of your sprite? What is the origin of your sprite?
Your BOUNDING BOX must be an odd number of pixels wide (so left is odd and right is even, or vice-versa). Your Sprites origin must be centered horizontally in the bounding box. These apply only to game maker Studio, sinse in older versions mirroring Sprites causes the bounding box to be resized.
 
I

IamN5

Guest
GameMaker Studio; my sprite is 64x64;where I can setup the bounding box?; the origin of my sprite is 32x32.
 

TheouAegis

Member
If you did not mess with the bounding box yet, then don't worry.

Did you set a collision mask in the object properties? If you did, that could be the problem. Your Sprite Properties by the sounds of it should be okay.
 
I

IamN5

Guest
I didnt mess with the collision mask yet.
EDIT1 = I had to change my walking sprite (it doesnt have the sword anymore, but the stand one has it so I can't leave the object without a mask or it'll glitch the sprite control)
 

HayManMarc

Member
If the sprite is set to "precise" and the pixels are not mirror image across the y axis of the origin, then there's a possibility that some pixels will share space with the wall, this causing the object to stick.
To remedy, unchecked "precise" and manually set the mask as a rectangle with equal distances from the left and right edges of the sprite. That way, when you flip the xscale, the mask stays the same.
 

TheouAegis

Member
Okay, I solved it for you.

First off, do not use a separate collision mask. Remove the spr_mask sprite and make sure your player doesn't use it.

Second, manually set all your collision masks for each sprite. They must all be the same. You probably do not want the mask covering the whole sprite. Very few games use a bounding box that covers the entire sprite.

Third, make sure the origin of the sprite is horizontally in the middle of your left and right bounds. So if your left bound is 22 and your right bound is 37 (the values I used), then the x origin of your sprite should be 30.

The parity of the left and right bounds may or may not need to be different (meaning one is odd and the other is even). If after doing steps 1 through 3 you still have the issue, then try changing the parity of just one of the bounds. Make sure you recalculate the origin's position if you do change the left or right bound again.
 
I

IamN5

Guest
Thanks for the help, now I got it.I thought that would not affect my game, because I was not using physics world.
I love GMCommunity :)
 
Top