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:
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:
- Get the 3D world position at the center of the sphere.
- Use Camera.WorldToViewportPoint to project the point to the viewport plane.
- Move a Sphere Collider with the radius of the sphere to that point.
- 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:
In the example above the cuboids are overlapping from the view of the player, but not colliding when they should be.
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?
EDIT: Corrected the images, before they were incorrectly projecting onto the y=0 plane at 0 rotation, not the plane parallel to the viewport plane.