Objects collision throught the camera

Hello everyone :slight_smile:

I’m playing with the collision sensor that works quite well in a 3D space. I’d like to get a collision but only from the camera even if objects are not really colliding.

Here is an example with two objects that are not intersecting each other but from the camera point of view, seen it as a “2D image”, the sphere is touching the cube.

In the opposite side, this shouldn’t be detected as a collision.

How could I get this information?
Is that even possible?

hmm…thats a tricky one…I would think there is a couple of easy ways to go about it…you could just shoot a ray from camera…and see if it hits both objects…but they would have to line up pretty good, as in your first picture, if you shot a ray, it probably wouldnt hit the sphere as its not dead center. You could try parenting a cone object to your camera representing your field of view and stretch it out a bit, and test collisions on tht object. Heres an example

Even though the objects arent actually touching. You could get a collision on both on the cone from the cameras field of view.Youd have to play with it to get it right, and others may have better suggestions. Bye

This looks like a pretty neat idea that could be used for some pretty unique and fun gameplay mechanics. However, it could be somewhat tricky to implement it in the BGE. In my head, this is how I imagine you’d do it.

  1. Transform the objects’ collision bounds using the camera’s transformation matrix (or some matrix derived from it, my linear algebra isn’t too good so I’m not entirely sure)
  2. Get the objects’ positions in 2D screen space
  3. Place the transformed collision bounds (which should now be 2-dimensional) at these locations and see if they collide

Unfortunately, you won’t be able to do #1 or #3 with Bullet’s current implementation as far as I know, so you’d probably have to implement your own collision bounds and collision detection.

Of course, there are other ways you could achieve the effect you’re going for, but I suspect that most of them either won’t be as efficient or as accurate.

I’d render a shadow map using only the “collision group” from the camera. You can then check who’s in the shadow, thus “intersecting” in the screen space.

Don’t know how fast would that be, or if it can be implemented, but on say Unity that would be the way I’d be going for.