• Advertisement
Sign in to follow this  

[Video Tutorial] Solving the "crack" collision problem (getting stuck between two tiles)

This topic is 1810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello gamedev, I made a video tutorial on how to solve a common problem encountered in 2D collision detection and resolution.
The issue often happens when your physical bodies live in tile-based environments. Sometimes the order in which the collisions are resolved is incorrect, and the physical body gets stuck between two tiles.
I've discovered two interesting ways to prevent (and fix) the issue, and I've created a tutorial video:



Video description:

Foreword: this is my first time doing a video tutorial. Please excuse me for any mistake, or if the explanation wasn't clear. I've also had some technical difficulties - my microphone is broken, and my webcam has a very poor quality. I recorded the tutorial (both audio and video) using my iPhone 4S. Unfortunately the quality of the markers I'm using is also poor - they're old and I couldn't find anything better, but I will buy some better markers tomorrow.
You can see an EXPERIMENTAL implementation of the merging method here:https://github.com/SuperV1234/SSVSCollision[3]
Additional information: I've already written an article about collisions. It's outdated, but some concepts can be easier to understand in the article. I talk about spatial hashing and "overlap area" sorting, albeit in a different (and less elegant) way. If you need more info on what I'm talking about in the video, the article would be a good place to start.
When I have time, I'll update the article and put it in my website. (http://http://vittorioromeo.info/[6] )
Please let me know if you need anything explained in the comments - and if you have suggestion on how I could record audio/video in a better way.
Thanks for watching.

Share this post

Link to post
Share on other sites

Well, the solution dosen't really work 99% of the time, because generally, physics engines don't like you to mess with how collisions are handled. Finding the area under the two tiles is easy. but, on messing with the collisions, weird things start to happen.


for example, consider a heavy box that is almost equally placed in between two tiles, but is still closer to one tile. Then, on ignoring the collision with the 2nd tile, the box will start to sink down the tile (as the collision will have been ignored). This will end up in the box sinking and finally dropping down completely. This is one example of the numerous weird artifacts you'll begin to see by messing with collisions.


Other weird things you're likely to see is tunneling, strange collisions, and objects getting stuck in strange ways(even though our original goal was to prevent objects from getting stuck ;) ). You have to be *very careful* when deciding to filter collisions and you'll almost always find some configuration that breaks your filtering rules. 


the second method is quite impossible to use unless you have a custom physics engine (or) you decide to hack the physics engine yourself.to combine / merge two tiles together during run-time, you'll need to remove the original tile  and then re-create two  new tiles and then put the new tile in the correct position.To do this every frame. incurs quite a performance cost.So, basically,  the technique is hard to implement as well as quite slow *UNLESS* you have your own physics engine, which most people have neither the time nor the inclination to build.



what I do is to pre-process the tiles.It's trivial to find the largest continuous, horizontal row of tiles and create that as a separate mega tile.ditto for the vertical tiles. I do this as soon as the level is loaded and BEFORE the tiles are sent to the physics engine. once I finish processing the tiles, I then send the large tile chunks to the physics engine. This eliminates the problem almost entirely. It's a simple solution to a weird and complex problem smile.png


Well, these are just my 2 cents smile.png

Edited by bollµ

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement