• 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 [SOLVED] Trouble with object > tile collisions

T

Tofu Heavy Industries

Guest
ok im having trouble with object > Tile collision in GM2. The player goes too far into the tile, once he walks into one, you can move out the opposite way but cant move up or down because hes a few pixels into the collision tile.

I have a room, and it has a tileset layer called collision.

in my players object : Start Room
Code:
tilemap = layer_tilemap_get_id("Collision");
heres in the players "Step" event. (Some unrelated stuff removed)
Code:
if (RIGHT == true) {
           if place_free(x+8, y) {
               move_right = true;
               if ((tilemap_get_at_pixel(tilemap,bbox_right,bbox_top) != 0) || (tilemap_get_at_pixel(tilemap,bbox_right,bbox_bottom) != 0)){
                   x += 0;
               } else {               
               x+= 4;
               }
}
}
Even when i set the collision box of the player to just a square, the player object still goes in 2-4 pixels deep. How do I prevent this?

youtube tuts didnt reference this usage exactly. and the tiles and player are both 16x16
 
T

Tofu Heavy Industries

Guest
Change the "x += 0" to something like:

Code:
while(tilemap_get_at_pixel(tilemap,bbox_right,y))
{
--x;
}
ill try that out.


I also found that this worked for me for moving right
Code:
if ((tilemap_get_at_pixel(tilemap,bbox_right+4,bbox_top) != 0) || (tilemap_get_at_pixel(tilemap,bbox_right+4,bbox_bottom) != 0))
For the others its Just adding the pixel number to the main cardinal direction. right + 4, left -4, up -4 , down +4
 
T

Tofu Heavy Industries

Guest
it isnt really solved, I made the sprites mask a full rectangle to have uniform collisions on each side. (with the pixels added to the bbox_'s). But weirdly, some of my tiles in the room are bigger and/or placed a few pixels upper or lower in the room. Grid snap is on, and the tiles fit into the grids i made on the background I use as a tile set. Its really weird!


Change the "x += 0" to something like:
Actually that creates an effect where the screen jiggles back and forth when you press up against one of these tile walls. Shakes the screen about.
 
Last edited by a moderator:
Top