Thread: clear collisions

  1. #1
    Registered User
    Join Date
    Nov 2003

    clear collisions

    I can check if 2 objects are colliding. But when to objects travel 10 pixels per frame and they are 2 pixels square then there is a change I won't detect it. How should I check if there is a collision or not and set the 2 objects in the corect position of where they will collide?

    Thanx in advance!

  2. #2
    Registered User
    Join Date
    Feb 2002
    The way to do it is to use collision in time.

    Say you have two objects with pos and vel as follows:
    p1 = (x, y) + t(a, b)
    p2 = (z, w) + t(c, d)

    where x, y (and z, w) is last frame pos, and t(a, b) is velocity times frametime. This is ordinary framerate regulated movement.

    now you can take these two points and write the relationship (distans) between then as an equation. Remember pythagoras??

    Now here is the cool part:
    what you have now is a function describing the distanse, and this distans depends on time!

    there are several ways to go from here:
    1. divide the frametime (t) into smaller parts and test each of these time slices for collision. less precision though.

    2. if you derive the original equation you get an equation where you have a minimal point. solve for t, and you will have the time when this min point occurs. great! now put this time in the original equation to get the minimum distans between the objects under the frametime.

    from here on either way goes the same: normal collision detection, either box, circle, pixelprecise. but now you have the exact time the collision will occur.

    Well this was kinda simplified, cause solving the equations takes one page when using pen and paper... there might be other ways to do this, this one being almost only mathematical...

    best of luck to you, hope any of this helped!

  3. #3
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Originally posted by ninebit
    1. divide the frametime (t) into smaller parts and test each of these time slices for collision. less precision though.
    //    float t = 1/FramesPerSecond; 
    float t = 1/(FramesPerSecond * 2);
    one problem with line 2 ^^
    you need a loop

    FramesPerSecond = 65
    average_time_between_frames = t =
    this is usually enough to detect a colision

    circle dection is quicker so its best to run it first. long as the
    radis's are set to the most distance vertce from its axis it will
    never produce a false negitave.

    pixelprecise - can u explan some more
    Last edited by Nor; 01-09-2004 at 06:43 PM.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  4. #4
    Registered User
    Join Date
    Feb 2002
    I agree that circle (sphere) should be used f possible, since it easy and fast.

    pixel precise, would be for a 2d game to test each pixel of the two collidion objects (bitmaps?) to see if there is a collision. although its quite nice to have this type of precision on the collision detection, I find that it is not worth it in most games, since the playser will never know the precission is that good anyway. obviously you should use circle or rect collision detection before you do pixel collision, if no collision in the first test, there will never be a collision in the pixel collision.

    This applies also to 3d games, but there you use polygonal precise collision once the bounding volumes have collided. poly collision would test every polygon on the two object to find collision, roughly speaking. there several ways to do this i'm sure.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well you do it in two steps

    Use a circle method which is quick, but you make the circle radius equal to the speeds of the objects.

    If they fall inside the larger circle, then you can do a more detailed calculation on the subset of objects which are "close" together.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About clear(). Please help!
    By Antigloss in forum C++ Programming
    Replies: 12
    Last Post: 07-14-2005, 04:02 AM
  2. How to Clear in Visual C++
    By MyDestiny in forum Windows Programming
    Replies: 4
    Last Post: 03-16-2005, 10:40 PM
  3. How to Clear in Visual C++ 6.0
    By MyDestiny in forum Windows Programming
    Replies: 1
    Last Post: 03-16-2005, 11:57 AM
  4. Yet another clear screen thread :D
    By kermit in forum Linux Programming
    Replies: 2
    Last Post: 11-20-2003, 05:14 AM
  5. Using a button to clear a list box!
    By Unregistered in forum C++ Programming
    Replies: 13
    Last Post: 08-23-2002, 07:44 PM