Project collision shapes to plane for 2.5D collision detection

Posted by Jkh2 on Game Development See other posts from Game Development or by Jkh2
Published on 2013-11-10T23:51:07Z Indexed on 2013/11/11 4:16 UTC
Read the original article Hit count: 355

Filed under:
|
|
|

I am working on a top down 2.5D game. In the game anything that overlaps on the screen should be 'colliding' with each other regardless of whether they are on the same plane in the 3D world. This is illustrated below from a side-ways view:

enter image description here

The orange and green circles are spheres floating in the 3D world. They are projected onto a plane parallel to the viewport plane (y = 0 in the image) and if they overlap there is a collision event between them. These spheres are attached to other meshes to represent the sphere bounding boxes for collisions.

The way I plan to implement this at the moment is the following:

  1. Get the 3D world position at the center of the sphere.
  2. Use Camera.WorldToViewportPoint to project the point to the viewport plane.
  3. Move a Sphere Collider with the radius of the sphere to that point.
  4. Test for collisions using unity colliders.

My question is how to extend this to work for rotated cuboids. For instance if I have two rotated cuboids, if I follow the logic above it would not work as intended as the cuboids may not collide but they could still be intersected on the view plane. An example is below:

enter image description here

Is there a way to project a cuboid that would be aligned with the plane? Would it be a valid cuboid for all rotations if I did this?

© Game Development or respective owner

Related posts about collision-detection

Related posts about unity