2
\$\begingroup\$

I have two objects that should collide. My player should stand on a ship. The position where my player stands, is exactly on the edge of two adjacent triangles (in the ship's model). To Check for collision, I'm using ray picking. I cast a ray from the player's hips downwards. This intersection tells me if the player should be falling (no collision), or if there is a floor under his feet (collision). In some occasions, the ray is fired exactly between two triangles, causing the ray to not collide, causing the player to fall through the floor.

I've solved this in my "RayIntersectsTriangle" function by slightly increasing the triangle's size. It feels hacky, and like it's bad practice.

I realise I could also solve this by casting multiple rays from the player downwards, and check if at least one collides. But obviously, this consumes more operations, and also feels like it should not be the way to do it.

FYI: The RayIntersectsTriangle function definitely works, no question. I'm just wondering if floating point precision is messing this up.

Is there a way to make sure that a raycast can never pass between two triangles in a mesh due to floating point errors, or should I make a workaround like I did?

\$\endgroup\$
  • \$\begingroup\$ Is there a specific problem you're looking to solve or answer you're looking to get? As it is, the question is pretty broad with "What do you guys think?", as there isn't a correct response. \$\endgroup\$ – ChrisUC Feb 19 '16 at 10:35
  • \$\begingroup\$ If the problem isn't a gap in your geometry, then you may want to look into implementing a watertight ray intersection algorithm. \$\endgroup\$ – DMGregory Mar 25 '16 at 16:08
0
\$\begingroup\$

Casting multiple rays won't hurt your performance much since your running time will still be O(n).

Another word of advice. Programming is a pretty messy enterprise. You shouldn't worry about something being "hacky" or bad practice if your solution works (i.e it doesn't cause bugs, runs in a reasonable time/space complexity). You'll find that a lot of things in game design and graphics are "hacky" but work (one such example is phong shading).

Hope this helps.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Not the answer I was hoping for, but it definitely helps. Accepted because It's a good answer. \$\endgroup\$ – Peethor Apr 25 '16 at 14:20

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.