Skip to content

Collision detection bug for certain face * face collisions. #2

@thomcc

Description

@thomcc

I believe I've found a bug in your physics or collision code. It's possible you're already aware of this, since after checking out older versions of the code, it seems to be present in all of them. The result of this bug is objects clipping through the geometry entirely.

An easily reproducible test case can be found by modifying your testphys/testphys.cpp code to only have a single cube that starts at {0.0f, 0.0f, 5.5f} (Here's a gist that has those changes available). When you run the program, it the cube will pass entirely through the world geometry as it falls.

I did a bit of sleuthing in a debugger to try and figure out the issue on my own. I did not have a ton of luck, but some. What I've found is that this seems to come from src.v in calcpoints ending up as a zero vector. Normalizing a zero vector ends poorly, and the rest of the code can't cope (and the simple solution of checking before normalizing and substituting a unit vector does not solve the problem). The zero comes from PlaneProjectOf returning zero on line 128 of gjk.h, but while I believe I understand that code, I don't understand it well enough to know how that should be handled (my guess is that that code is fine, and the caller should be checking for the zero vector).

A few things I've found do solve (well, avoid) the problem that might help track it down:

  • Changing the starting position so that the x and y positions are not 0, 0. For example, going from {0.0f, 0.0f, 5.5f} to {0.0f, 0.1f, 5.5f} avoids it.
  • Certain starting z positions don't trigger it. E.g. 1.9 won't, even though 1.85 and 1.95 will. Nothing below 0.7 seems to trigger it (until the cube begins to start inside the world geometry, at which point it always happens).
  • Changing the orientation so that the collision does not occur as face * face avoids it.

Probably worth mentioning that I'm on a mac and using clang, and am using a modified version of glwin.h (you can see it here) that uses SDL to allow running from a mac. I don't believe this to be related in any way, since it happens at all optimization levels and otherwise works perfectly, but I obviously could be wrong.

P.S. This is a great project. Very straightforward code, not bloated or overengineered. Extremely pleasant to read through and learn from. Thanks for sharing it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions