1
\$\begingroup\$

In the collision system for my game I basically have two kinds of things, boxes, defined thusly:

struct Box2I
{
    uint32_t x, y, width, height;
};

and quads, which are used for terrain:

struct Quad
{
     const uint32_t left, right;
     const float slope_top, intercept_top;
     const float slope_bottom, intercept_bottom;
     bool solid;
};

The boxes can collide with the quads, but the boxes can't collide with each other, and colliding quads has no meaning.

Anyway, I'm having trouble with the collision, the collision function should return a number between 0.0 and 1.0, where 0.0 is the time of the last frame, 1.0 is the time of the next frame--and -1 for no collision. But I can't find a way to do this.

Mostly I can find algorithms for systems such as colliding circles, where they move but the scale doesn't change, or points, etc. But I'm having trouble finding anything beyond the general scheme of:

  1. broad phase checks
  2. ?????
  3. binary/interpolation search for collision time

And I'm just not sure what goes in 2, because I frequently find things on the separating axis theorem, but that can't be #2 because objects would sometimes tunnel. The other general idea I've come across is casting rays from each of the corners of the box, but again, I can see that sometimes allowing tunneling.

What's the general technique that's typically used here?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.