SOLVED Tile collision rectangle

TailBit

Member
I have seen the tile collision tutorial with slopes, pretty neat, but I've been trying to figure out how to detect where to end up when you will hit the ceiling, and I have more rectangular collision box..

For the first one, I did manage to figure out that I had to find the room between them on the left side when moving in .. and the height available need to be (height + width -1) .. then it should be possible to use some formulas to figure out the x for that space .. so that one is fine.

But the 2nd one, could be that I have been thinking too much, but do anyone have a suggestion how I should detect collision for the 2nd to avoid checking pixel steps?
 

Attachments

Yal

šŸ§ *penguin noises*
GMC Elder
Instead of checking pixel steps, you could just check the tile type, and map that somehow to a different collision function: pure decorations have a function that just return "okay it's no collision here", most boxy tiles has the opposite where it's always a hit, and slopes would use point_in_triangle to check if the point is inside the ground/roof or not. Longer slopes (e.g. 2-wide 1-tall) will have a triangle that sticks outside of the tile - since it needs multiple tiles to make an entire segment of slope - but we can safely ignore that since we already know we're checking a point inside the tile at this point.

The tricky part is the mapping from tile index to tile type. I personally prefer having my tiles arranged in vertical columns that each have the same type, so you only need to check the x coordinate (or in GMS2, the tile index divided with the sprite width divided by the tile size).
tileset_cave.png
 

TailBit

Member
My problem was that moving too fast will make it skip the collision check in the halftile..

But after a rest I figured I have to check the height position it would leave the tile at, and if too high then I would have to use the new allowed height to find out where in the slope I would stop.

The rest of the tile collision was pretty stright forward .. so it is solved.
 
Top