Easy Tile collision - Tutorial - GMS2

preview_player
Показать описание
Ever wondered how to make easy tile collisions? Then this video is what you are looking for. I will explain how my collision script works, and how to use it.

The script is really small and easier to code than other solutions i have found.

I really hope you will enjoy the content ^^

►Follow me on Twitter for more regular updates
Рекомендации по теме
Комментарии
Автор

Epic idea! Thank you for this code. I had a thought to improve the 'meeting =' part of this with a loop to check for all pixels along the BBox edges:

var meeting = false;
for (var i = bbox_right; i <= bbox_left; i++)
{
meeting = tilemap_get_at_pixel(tilemap, i, bbox_top);
if (meeting) { break; } //kill the for loop once we hit something
}

You have now checked for one entire edge of the bounding box.

Do the same but iterating between bbox_bot and bbox_top while keeping bbox_right as your X-coord, and you've got another edge. Do it twice more for the remaining edges and you've checked all pixels along the bounding box.

For more precise collision-checking. :)

P.S.
Also remember to check before running those three other for loops whether meeting == true already. We don't want to run additional tests (and potentially invalidate the result of the first) if we already know that we've hit something.

Shrooblord
Автор

this doesn't work unless you replace
tile_meeting(x+sign(spdx), y, "Tiles_1")
with
tile_meeting(x+sign(spdx), y, )
Then it works great!Thanks!

RhanW
Автор

Dude thank you so much, this saves me so much time!

softbabymonkey
Автор

For me it clips into tiles if it hits them on the corner. Is there any way to fix it?

cossin
Автор

I'm new to game maker studio. How did you get the GML editor window on the right side of another one? And what is

evanroderick
Автор

Can i use this code in my commercial game?

mehmetyigitkeskin
Автор

hey man, it seems the script is working, cuz i'm not getting any errors and the game runs. But my player-object still doesn't collide with said tilesets that I use for collision, it just goes through. Now i already checked the width and height of the sprite and it's even smaller than the tile.

takomeulenbeld
Автор

Can you please make a video that uses tile collision but links up with your "perfect top down movement video" I can't seem to figure out how to apply this with the velocity array method you used in the other vidoe

MrJacovorster
Автор

Hello, thank you for taking the time doing your tutorial.

I've a question: Well, actually I don't quite understand how the spdx and spdy are called, I tried the code exact in my game but it tells me that such variables aren't defined; so I placed instead the hspd and vspd my character uses to move, but it still says the same...

How do I make the End Event realise that they are already declared? Thank you.

FaramurDodecuai
Автор

So I messed around with this, and it works GREAT- that is UNTIL you try to use a Gamepad for controls. Then it stops working altogether. Anyone out there have any troubleshooting advice? I feel like I'm SO close to getting this to work! Thanks!!

RagingSunbeam
Автор

so it says tile_meeting isn't a function in my version but it is the latest gms2. What should I use instead?

veruticon
Автор

The whole "move player into the wall then move them out" is a very messy approach; it's much better to check your x/y value plus your speed variable for the tile, then use a loop to make sure you can approach the tile without going into it

conoma
Автор

Nice, I liked it.
Easy to follow, familiar concepts (at least for me anyway). You should have mentioned though, that this doesn't handle slopes/curved tiles, though I guess that's why it's "Easy"

blazecreates
Автор

it says the variable spdx isnt defined :(

TToxicom
Автор

It doesn't work. It always occurs the error:
tilemap_get_at_pixel() - couldn't find specified tilemap
Can anybody help me?

PoseidonLP
Автор

You seem to be performing the 4 collision checks X's 4 making 16 checks and this is assuming you have only collided somewhere by a single pixel. If not you run while(!tile_meeting) multiple multiple times. This is EXTREMELY inefficient code which there seems to be little point in. I am ok with inefficient if it gets the job done no other way could be this seems extremely pointless to do all 4 checks when you could get away with a single check in the while loop can't you?

seditt
Автор

hmmm... my character goes straight through, no matter what... gms doesn't give me any errors, so, I don't know what's going on !

morphball
Автор

You're using a loop in place of basic math. So much extra stuff going on for no reason.

badwrong