Thread: 2D Collision Detection/Handling

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262

    2D Collision Detection/Handling

    Hello all,

    I have some experience with the maths for 2D physics, including collision detection. So my question is not about how to detect if a circle intersects a polygon, I can do that. However, with all these "basics" I know about, I don't know how to properly simulate real-time physics.

    As far as I know, most real-time physics engines first update the movement of all objects as though there was no collision and then "solves" the collisions, by moving back objects until no collisions occur. However, what is a good algorithm for resolving these collisions? Also, is there a better algorithm, maybe slightly slower but more accurate and still fast enough for a decent 2D game?


    Thanks in advance,
    EVOEx

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    As far as I know, most real-time physics engines first update the movement of all objects as though there was no collision and then "solves" the collisions, by moving back objects until no collisions occur.
    O_o

    I don't know about "most". I've seen a few that work in such a way as to update real objects twice without drawing between updates. (The objects are "moved" normally and then physics is applied resulting in a second movement.) I've seen a few a that work by rolling all updates, like movement, entirely into the physics engine. (The objects are "moved" indirectly through the physics engine with the engine fixing the ultimate location.) Most of them I've seen the last few years use "stepper" routines to apply physics over a given time which ultimately modifies aspects of the object with callbacks "fixing" aspects like position, acceleration, and mass. (The objects are again "moved" indirectly through the physics engine but only by means of object specific callbacks.)

    Also, is there a better algorithm, maybe slightly slower but more accurate and still fast enough for a decent 2D game?
    Probably, but you haven't told us what algorithms you are using so who knows.

    Why don't you take a few minutes to describe exactly what aspects of physics you are simulating and how you are simulating them. That's pretty much the only way we have a chance of suggesting things that might be "faster", "better", or "more accurate".

    Soma

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Thanks for your reply, phantomotap.

    Well, that's kind of my problem (sorry for being unclear); I don't have an algorithm yet because I don't know which to use. That was my attempt of asking ;-). Basically, I want to write a physics engine but don't know how to do the collision resolving in there.

    I've looked at how chipmunk does it, and some other physics engine of which I don't remember the name. They both had several "steps" to move the objects (I believe 10) per rendered frame. But then when it actually detects the collision it uses another "10 steps" (by default) to resolve the collision, if I'm not mistaken. But I'm unsure how this resolving step works completely, so that it is at least visually accurate.

    So, what are some good algorithms for this? Remember this is quite general purpose, for 2D physics.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The first hit for "2d physics collisions" gives me: Rigid Body Dynamics - Chris Hecker's Website
    The second gives me this: 2D Collision
    The third: http://www.euclideanspace.com/physic...twod/index.htm

    All three look like interesting starting points.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by quzah View Post
    The first hit for "2d physics collisions" gives me: Rigid Body Dynamics - Chris Hecker's Website
    The second gives me this: 2D Collision
    The third: Physics - Collision in 2 dimensions - Martin Baker

    All three look like interesting starting points.


    Quzah.
    Thanks for your help guys. I was looking more for an overview of available algorithms. The first one described one that seems good enough for me, though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Collision detection
    By jack_carver in forum C Programming
    Replies: 5
    Last Post: 02-08-2010, 06:52 AM
  2. Collision Detection
    By Grantyt3 in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2005, 03:21 PM
  3. Collision Detection
    By cboard_member in forum Game Programming
    Replies: 2
    Last Post: 08-06-2005, 12:14 PM
  4. collision detection
    By DavidP in forum Game Programming
    Replies: 2
    Last Post: 05-11-2002, 01:31 PM
  5. Need collision detection!(HELP!)
    By SyntaxBubble in forum Game Programming
    Replies: 1
    Last Post: 02-27-2002, 06:13 PM