• 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 Collision problem

Hi, I´m making a tile based collision system and I use this script:
GML:
var _collision = false;

//Tiles horizontales
if (tilemap_get_at_pixel(collisionMap, x + hSpeed, y))
{
    x -= x mod TILE_SIZE;
    if(sign(hSpeed) == 1) x += TILE_SIZE -1;
    hSpeed = 0;
    _collision = true;
}

//Cometer movimiento horizontal
x += hSpeed;

//Tiles verticales
if (tilemap_get_at_pixel(collisionMap, x, y + vSpeed))
{
    y -= y mod TILE_SIZE;
    if(sign(vSpeed) == 1) y += TILE_SIZE -1;
    vSpeed = 0;
    _collision = true;
}

//Cometer movimiento vertical
y += vSpeed;

return _collision;
The problem is that I want to increase the number of pixels that my character detects to stop horizontaly.
Because my charachter´s leg trespass the collision block. I´m ok with the vertical collision but not with the horizontal collision. What can I do? By the way, It´s origin is on the bottom center.
 

Slyddar

Member
You need to adjust the sprites collision mask to cover the area where you want the collision to occur.
 
You need to adjust the sprites collision mask to cover the area where you want the collision to occur.
The problem is that my character´s collision isn´t the collision mask, it´s the origin. How do I replace the collision with the collision mask?
 

jobjorgos

Member
do something like this and the character will stop 20 pixels early (if your hSpeed is 2 or -2)
GML:
if (tilemap_get_at_pixel(collisionMap, x + hSpeed * 10, y))
 
Last edited:

Slyddar

Member
The problem is that my character´s collision isn´t the collision mask, it´s the origin. How do I replace the collision with the collision mask?
Your tilemap collision check should not be just checking one pixel, but there should be 4 checks at each corner of the mask instead, as that will cater for the collision mask. Use bbox to get those positions. You can also make a place_meeting_tile function which does this check for you, checking the origin and the 4 corners. As long as your mask dimensions are smaller than your tile size, it will work fine.
 
Top