• Create Account

## Simply Grasping Collisions and Contacts

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.

18 replies to this topic

### #1bennettbugs  Members

493
Like
0Likes
Like

Posted 22 May 2012 - 10:43 PM

I have spent numerous hours and days trying to grasp these... Starting with a wonderful idea or theory, but then i start to think of scenarios for that theory, and it falls apart. I know it is abstract, and I can see how it would be that way... but I cant figure out how to calculate simply when 2 boxes are touching. I have a lot of graph paper with theorems and ideas, but i only have one uploaded since it was the most concrete, but still didnt work out... (in attachments)

So im wondering... can simple 2D box collisions be simple? Or am I taking it too lightly?

### #2Lightness1024  Members

920
Like
0Likes
Like

Posted 23 May 2012 - 02:14 AM

I'm not sure from your drawing, are you trying to compute box/box collision onlu from the corners and velocity rays ?
have you considered the fact that your collider can be a smaller object than the box ?
you need to consider edges crossing as well.
also, intersection, collisions, and response are three different things.
intersection doesn't consider movement, "collision" suggests a sweeping volume, response is "physics"
maybe that'll lead you to a more structured thinking

### #3Hodgman  Moderators

49386
Like
0Likes
Like

Posted 23 May 2012 - 02:28 AM

### #4bennettbugs  Members

493
Like
0Likes
Like

Posted 23 May 2012 - 03:53 PM

Yeah, thats one of the reasons why it fell apart. I know everything but the process of actually detecting collisions (which is not much). I have been trying to basically memorize and understand completely how one would go about collision resolution. I know there are a lot of pages on how to detect them, like Hodgman's link, but I am talking about a more in-depth, explanation of every single little step there is and why that step is there. I just got done reading this book:
http://www.amazon.com/Physics-Engine-Development-Second-Edition/dp/0123819768

But it did not explain why some of the steps were in there, but rather just described what it did. If there are any resources on collision detection and that fit what I stated before, please post.

Also, I hope I am not the only one having trouble with this. Hopefully this can help anyone else who too has the same problems.

### #5bennettbugs  Members

493
Like
0Likes
Like

Posted 23 May 2012 - 03:58 PM

Also, my drawing shows my thinking of how to detect collisions or contacts by checking velocities. If you want to know more about it, please ask. It is my best "Theory" (I guess you could call it), because none of my other ones have lived to make it too code. But it does not work, because smaller object than it wont collide.

### #6jefferytitan  Members

2508
Like
0Likes
Like

Posted 23 May 2012 - 04:17 PM

I gather from your diagrams that you're talking about collisions between 2D axis-aligned boxes moving in any direction? It sounds like you understand a fair bit of it from reading papers etc. Are the specific areas that you're stuck on?

### #7bennettbugs  Members

493
Like
0Likes
Like

Posted 23 May 2012 - 04:47 PM

Basically understanding why the steps of collision detection need to be there. And yes, it is 2D. But i plan on also using it for my 3D game since it wont need rotation physics. But im stuck on the steps of collision detection.

### #8jefferytitan  Members

2508
Like
0Likes
Like

Posted 23 May 2012 - 06:02 PM

Whether it's complex depends a lot upon what your expectations are. Here's a few examples:

1. Detect whether two boxes are intersecting at a specific moment of time: Easy.
intersecting = (b1.left < b2.right) and (b1.right > b2.left) and (b1.top < b2.bottom) and (b1.bottom > b2.top)
2. Detect whether two boxes may have collided (e.g. swept out the same area within delta time d): Medium
intersecting = does polygon swept out by b1 within time d intersect with polygon swept out by b2 within time d
3. Detect whether two boxes did collide (excludes swept out same area but missed): Medium-hard
intersecting = find a time t such that the conditions in 1 are all met, taking velocity into account. Umm... take a look at this:
http://en.wikipedia....inear_equations

Those may not be the best options, just what occurred to me. Generally it is assumed that the timestep and speed of objects is such that you wouldn't need to go further than step 2. If objects move that fast or are that small it is hard for a player to interact with them.

Edited by jefferytitan, 23 May 2012 - 06:03 PM.

### #9bennettbugs  Members

493
Like
0Likes
Like

Posted 23 May 2012 - 07:39 PM

My expectation, or what I need is an impulse based collision system, and possibly later include rotation. But as it seems, I really suck at collision programming. :-\

Mainly I am hoping to come across a nice article on basic collision resolution, that describes each step and why that step is needed. For some reason, I cant utilize a strategy without knowing why it is...

### #10jefferytitan  Members

2508
Like
0Likes
Like

Posted 23 May 2012 - 08:10 PM

No need to put yourself down yet; there's always time later.

I'm not aware of such an article off the top of my head (not to say it doesn't exist). Just for starters, did my post on how to detect if there was a collision make sense? I can explain in more detail.

### #11bennettbugs  Members

493
Like
0Likes
Like

Posted 23 May 2012 - 08:43 PM

Yeah, those make complete sense, and I know exactly know why it is like that: because you are checking each axis. But something more complex, like... having rigid-body physics... :-\

Im looking forward to something like that. Thats why I read that book about it, but it did not explain it in such a matter that helped me completely understand it.

### #12jefferytitan  Members

2508
Like
1Likes
Like

Posted 23 May 2012 - 09:36 PM

There are two major problems:
• The physics of arbitrary collisions without rotation isn't natural, so requires assumptions from the programmer.
• Single collisions are easy(ish), multiple simultaneous collisions are hard. Proper physics engines have solvers that take many iterations to try and resolve the many constraint violations caused by solving the collisions locally. So for example, if blocks A, B and C are in a line and hit on the end by block D, firstly momentum will be transferred to block C. But that causes a collision with block B. Solving that causes a collision with block A. If block A is "free" it can then shoot off like a Newton's Cradle. If block A is pressed up against a wall, then this needs to be propagated all the way back to D.
Basically I'm saying that if you're trying to do single collisions, that's cool and probably easy. Anything else... is really a hard problem, so no wonder it's confusing you.

### #13bennettbugs  Members

493
Like
0Likes
Like

Posted 23 May 2012 - 09:41 PM

XD Yep. And since this is my first time doing everything, its a lot harder.

I bet if like the way i have come along, which is to start as simple as possible, then progress to harder things, i might be able to learn something. But if anyone has any links or tutorials even, it would be greatly appreciated.

### #14raigan  Members

1024
Like
2Likes
Like

Posted 24 May 2012 - 08:45 AM

I appreciate your struggle, it can definitely be a lot to wrap your head around (I don't really feel like I truly understand anything about collision yet either).

One resource that you might find edifying is Paul Firth's excellent tutorial, which covers a lot of material: http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/

Personally, one concept which has really helped me better understand collision is Minkowski sums (or differences); for your example of two axis-aligned rectangles, imagine reducing the width and height of box A to 0 (so that the box becomes a point) while simultaneously increasing the width and height of box B by the same amount -- you now have a point A and a box B, which is simpler to visualize/think about, and completely equivalent to the original problem.

Separating collision detection (geometric queries) from how you use the results (collision resolution/solving) can also help make the problem easier to understand. In terms of solving a set of constraints, this is another great overview to start with: http://www.wildbunny.co.uk/blog/2011/04/06/physics-engines-for-dummies/

### #15wildbunny  Members

550
Like
1Likes
Like

Posted 24 May 2012 - 12:55 PM

Thanks for posting those links Raigan

The OP might also appreciate this article, in which I describe generating the full contact set (among many other things) from the closest feature pairs returned by SAT, or minkowski difference:

http://www.wildbunny.co.uk/blog/2011/06/07/how-to-make-angry-birds-part-2/

Just part of implementing a physics engine capable of playing angry birds - hence the title

Cheers, Paul.

### #16bennettbugs  Members

493
Like
0Likes
Like

Posted 24 May 2012 - 04:43 PM

Thanks!

These look really good, I plan on reading them all tonight. It looks really well made, too.

### #17bennettbugs  Members

493
Like
0Likes
Like

Posted 27 May 2012 - 08:47 AM

So im doing some testing, and got point-box collisions working well. although since the game runs slow sometimes, the dots will pass through walls... but i can fix that.

But it runs fine regularly... and im hoping to move on to some other different collisions...

### #18Lightness1024  Members

920
Like
0Likes
Like

Posted 30 May 2012 - 02:51 AM

well for point to box you can specially design a "closer distance contact" function to avoid passing through boxes.
(raycasting) this function is made by solving the system made of the equations of a line (your ray) and the planes of the boxes.
in this case you would have implemented "swept collision".
also, you need to run your physics/collision loop in a fixed time step.
also, an idea for later, some engines does not run the collision detection at every simulation step.

### #19bennettbugs  Members

493
Like
0Likes
Like

Posted 30 May 2012 - 08:57 AM

Well, since it it tile based, it checks for collisions each time it crosses over to another block. it is slow because i have never wanted to take the time to make it more efficient, and im using fraps.

Since it uses it's velocity to check for the next box, when it is slow it will check far away. if you use +1 to its position, it will bounce when 1 unit away. if you use just its position, it will get stuck. :-\

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.