Help with collision detection (through code)

Yet again I am having problems with collision detection in my game.

Here’s the situation. I basically have a snake as a character, and the wiggling is done with a chain of bones. I’ve been trying to add collision for the snake with a SphereCast on each bone/link. This partially works, however the problem is that it has the same limitation as a regular raycast in that it cannot detect backfacing sides. Apparently the fact it’s a sphere doesn’t matter; it’s still only detecting along one line, it’s just a thicker line. So if an object passes through it from certain positions, it won’t detect any collision at all because the polygon is backfacing.
I also tried using a CapsuleCast, but it has the same problem, although handles it a lot better due to casting in two directions rather than one. But it still misses a lot of collisions.

What I really want is just something like the CheckCapsule command, which has no problem detecting every collision, however it’s completely useless for anything more than saying “Yep, you’re touching something”, but I need it to return the specific GameObject itself. I don’t need any information about the specifics of the collision beyond the GameObject.

Is there any foolproof way of detecting a collision within a volume through code that will not miss collisions?

(And before anyone asks, I can’t do this with regular colliders, because none of my movement or collision is done through rigidbodies. No physics at all.)

You can still do it with regular colliders. Just use the isTrigger flag. That would be by far the easiest way.

http://unity3d.com/support/documentation/Components/class-BoxCollider.html

But according to the collision matrix, triggers do not detect any collisions with other regular colliders. Or do you mean to make them rigidbody triggers?

not sure, you might have to make them kinematic rigidbody trigger colliders.

Yep, looks like kinematic rigidbody triggers will do exactly what I need. Thanks for the help! :smile: