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

Problem with coding half-tile collisions (Tiled Platformer Example GM Stuido 1.4)

I'm using the Tile Platformer example included with Game Maker Studio 1.4. I took some time to try to understand the code and what it does and I think I have a grasp on it. I'm expanding the tileset to include half-blocks and some slopes. I'm coding the collision for the half block here:

---STEP EVENT---

Code:
///calculate players tx and ty
sx=(x+sprite_width/2) div 16 * 16
tx=floor(x+sprite_width/2-sx)

sy=(y+sprite_height) div 16 * 16
ty=floor(y+sprite_height-sy)

Code:
   f2 = -1; //initializing collision variable
    f1 = GetCollision(x,y+sprite_height); //test for collision at bottom left of sprite
   
    f3 = GetCollision(x+sprite_width/2,y+sprite_height) //test for collision at bottom
                                                        //bottom middle of sprite
   
    if( (x&TILE_SIZE-1)>0 ) //if player x position not aligned with x axis
        {
        f2=GetCollision(x+sprite_width,y+sprite_height);//check bottom right
        }

if( f1==1 || f2==1 )  //if collision points detect the half tile block
        {
        if  (ty >= TILE_SIZE/2) //if player's ty position in tile is more than half through
            {
            y = (y&-TILE_SIZE/2); //snap player out
            jump=0;
            on_ground=1;
           
            if( dir=1)
                {
                sprite_index = spr_walk_right;
                }
            else
                {
                sprite_index = spr_walk_left;
                }
            }

        }
"ty" refers to how far into the tile vertically the player's hotspot is (the hotspot is in the middle of the sprite at the bottom). Tiles are 16x16 so if the ty variable is 8 that means the hot spot is halfway down the tile. This doesn't detect collisions though, just how high or low that hotspot is in the tile.

"f1" and "f2" are collision points to the bottom left and bottom right of the player. Those are the collision points that will detect the half tile (or any tile)

So ideally the logic should mean that as soon as either collision point reaches the beginning of the half-block tile, the ty equals 0, and the player should do nothing but fall until the player's ty is at or above 8.



The problem here is that it seems like it runs through the code once it detects the tile, instead of also seeing what the player's ty is. This makes him do a quick jittery motion as if he landed on a phantom platform. What's odd is that it'll seem to happen when the player just falls off a short ledge, instead of just jumping onto it normally. I'm hoping maybe you can see something I don't because I've been at this for days.
 
Top