• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 Tile Collision

Excuse me sorry to bother but I need some assistance regarding tile collision. You see I'm trying to make a fan Pac-Man game but I'm struggling to make the tile walls solid for Pac-Man to get blocked by. Is there an easy way to make it so this doesn't happen again or is there a specific code for Pac-Man related stuff?


First of all, how are you "moving" pacman? If you are using drag'n'drop, sadly the tiles don't count as "solid".
If you're using GML (the script language) then there are scripts for detecting collision with tiles, and you can make it so that if it isn't the "floor" or "emptiness" then it's solid and you can't move.

Please give us more details, example of codes you've tried and maybe screenshots so we can help you better!


Ok, first off, I'll go with whatever someone else had said about storing all the tiles to a data structure, like an array. Studio 2 has good tile handling functions, but still, the less often you call a tile function, the better. Reading an aray is going to be faster than looking up tiles. With that said.... Considering how new you are, I'll just stick with tile collisions.

Second, I might have gotten you confused with this guy, who was also doing a Pac-Man style game:

You can see a DnD code I drafted up for him. Not sure how accurate it was, because he never replied. lol Still, the principle is there for the ghosts.

You can still use DnD to handle tile collisions. You use the action
Get Tile Data At Pixel

You'd want to set the x AND y values to be relative and you'd just use your tiles' height or width as the offset for whatever direction you're looking. I think it's stupid you have to mark x and y both as relative separately, but whatever -- hooray for flexibility! Also, this function saves the result to a variable. You may as well make it a temp variable, since it's probably useless outside this code.

Anyway, let's assume your tiles are 64x64. If you want to check for a tile moving right, you'd put 64 in the x. If you want to check for a tile moving left, you'd put -64. To look up, put -64 in y. To move down, put 64 in y. Pretty simple.

The GML equivalent is tilemap_get_at_pixel(). More on the function here: https://docs2.yoyogames.com/

I don't have GMS2 anymore, so that's about the extent of my help there. lol I never messed with tiles enough when I had it...