Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 SuperV1234   Members   -  Reputation: 375

Like
0Likes
Like

Posted 08 February 2013 - 08:39 AM

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.
 
crackProblem.png
 
I've discovered two interesting ways to prevent (and fix) the issue, and I've created a tutorial video:

Enjoy!
 

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.
http://veegamedev.wordpress.com/2012/08/14/getting-2d-collisions-right-part-one/[4]http://veegamedev.wordpress.com/2012/08/14/getting-2d-collisions-right-part-two/[5]
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.



Sponsor:

#2 bollµ   Members   -  Reputation: 354

Like
0Likes
Like

Posted 09 February 2013 - 08:54 AM

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µ, 09 February 2013 - 09:02 AM.

a WIP 2d game engine: https://code.google.com/p/modulusengine/

English is not my first language, so do feel free to correct me :)





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS