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

GameMaker tilemask collisions

K

Kyle Rider

Guest
I am now running 60 FPS and I have seen a lot of things improve in my game. Things I couldn't imagine like just how smooth the animations run.

My collision system went to 💩💩💩💩 and I am trying to comprehend why. If my player jumps(from the ground) and lands a 32x32 tile higher he will glitch. If he jumps to a ledge that is 64 pixels higher he wont glitch.

When I say glitch I mean that he "soft lands" at 32 pixels and then proceeds to land on the ground.

Am I doomed?
 
K

Kyle Rider

Guest
It is a bit of a mess.

Code:
// TOP COLLISION //
//////////////////////////
c5 = tilemap_get_at_pixel(obj_Game.map,x-12,y-64) & tile_index_mask;  //top left for top collisions
c6 = tilemap_get_at_pixel(obj_Game.map,x+12,y-64) & tile_index_mask;  //top right for top collisions

if ((c5 == 2) ||(c6 == 2))
{
    jump = false;
    grav = gravmax;
}   

//JUMP MOVEMENT//
if key_jump != 0
{
    if jumps <= jumpsmax
    {   
        if jumps = 0
        {
            //audio_play_sound(sfx_jump,1,0);
        }
        if jumps = 1
        {
            //audio_play_sound(sfx_dbljump,1,0);
        }
        grav=grav_jump;        // make the player jump
        jump=true;
        jumps++;
    }
}
Here is my fall script.
Code:
//APPLY GRAVITY//
////ANIMATION////
/////////////////
y = y+grav;
grav+=gravdelta;
if( grav>=gravmax) grav=gravmax;

if( grav<0 )
{
    sprite_index = spr_vjump;
} else {                                    // otherwise, falling so check UNDER the player
    if(jump){                                // if coming down after jumping display the correct sprite
        sprite_index = spr_vfall;
    } else if(fall){                        // if falling from an edge display the fall sprite
        sprite_index = spr_vfall;
        jumps++;   
    } else {                                // if not already falling or jumping
        grav = 0;                            // first stop falling (used for ladders)
        fall = true;                        // flag that we are falling
    }
    // check the points at the bottom of the player character
    c1 = tilemap_get_at_pixel(obj_Game.map,x-12,y+1);    // left_bottom
    c2 = tilemap_get_at_pixel(obj_Game.map,x+12,y+1);    // right_bottom
    c3 = tilemap_get_at_pixel(obj_Game.map,x,y-1);// center for ladders!
    c4 = tilemap_get_at_pixel(obj_Game.map,x,y+1);    //CHECK FOR LADDER BELOW

    if( c1>=1 || c2>=1)
    {            // if they are intersecting with a tile
        if((c1 == 1) || (c2 == 1) || (c1 == 2) || (c2 == 2) || (c1 == 4) || (c3 == 4))
        {
            y = real(y&~31);            // move the sprite to the top of the tile
            sprite_index = choose(spr_vidle);    // set the sprite to the idle sprite
            climbing = false;                // stop any climbing
            jump = false;                    // stop any jumping
            fall = false;                    // stop any falling
            jumps = 0;
        }
        if((c3 == 3) || (c4 == 4))
        {            // if we are intersecting with a ladder
            can_climb = true;
            if(c4 == 4){
            if (key_down != 0)
            {
                y = y + 1;
                state = states.ladder;
            }
        }
        if(c3 == 3){                            // if we are intersecting with a ladder
            can_climb = true;   
            if (key_up != 0)   
            {
                state = states.ladder;
            }       
        }                // flag that we can climb
        }
    } else {                                // if we are not intersecting any tiles
        climbing = false;                    // flag that we cannot climb
    }
}
 

TheouAegis

Member
You didn't mask your c1, c2, c3 and c4 in your fall script, but that maybe just isn't an issue for your game.

Rereading your issue, it actually almost sounds like you had something that tells the player to drop to the ground if there is ground 32 pixels below him. Since if you jump 64 high, then 32 pixels down there's no ground and he stays on the 64-high plat, but on the 32-high plat there's ground below.

Did you test jumping OVER onto a 32-high plat, rather than straight up with no ground under the plat? So like this:
Code:
PPP
               PPP
XXXXXX          XXXXX
So X would be ground, P would be a "floating" platform. The first set of Ps are 64 pixels above the ground. The second set of Ps are 32 pixels above the ground with no ground under them for the player to fall down onto.

However, depending on how you were phrasing it, maybe you meant something more like this was your setup:
Code:
PPP
PPP
XXXXXXXXXXXXXX
Here the platforms are over each other. In which case, I'd suspect that maybe the ceiling collision code is detecting the platform overhead and making the player fall, which causes the player to fall below the lower platform onto the ground. When you're on the top platform, there's nothing above so.
 
K

Kyle Rider

Guest
do you mean adding in & tile_index_mask? Yeah that doesn't seem to have an effect in GMS 2.

I took a screen, if I jump on the red spot up and down then there is no glitch. I also caught this screenshot right where he does his odd jump.
 
K

Kyle Rider

Guest
Also, Looking at GM Wolf's tilemap tut on YouTube he made 4 variables for the bounding box of his character. Is this required in your opinion?
 
K

Kyle Rider

Guest
Looking at the code I have fixed up a few things and I am really happy with my x collision now. Hahaha, still having a glitch on Y down, fixed my Y up.

I figured it out! HA!

A couple posts back someone suggested I add +1 to my Y collision and it didn't help but it didn't hinder so I left it. moving to 60FPS made the problem appear. It works perfect now that I removed the +1 to my Y here:
Code:
    c1 = tilemap_get_at_pixel(obj_Game.map,x-12,y+1) & tile_index_mask;    // left_bottom Not Working

    c1 = tilemap_get_at_pixel(obj_Game.map,x-12,y) & tile_index_mask;    // left_bottom This Works
 

TheouAegis

Member
As for the 4 points issue, it's pointless checking all 4 points at once. And personally I use 6, 7, 8 or 9 points. You had the right idea, but you need to encapsulate the variables inside the conditions based on direction. For example, your code should be narrowed down to just 2 collision variables, c0 and c1. Are you moving up? Then c0 and c1 are the top-left and top-right bounds. Moving right? Then c0 and c1 are the top-right and bottom-right bounds. Moving down? Then c0 and c1 are the bottom-left and bottom-right bounds. Moving right and up? Well, pick one direction to check for collisions with at a time, I guess.
 
K

Kyle Rider

Guest
That is exactly what I did and it all works much faster now. I re-read the my X code and it was more confusing then the Y. I owe you big Theou!
 
Top