- Home /
how to check if 1 sided plane is facing the camera
if I have an array of planes and I want to know which ones are facing the camera, how do I do it? I figure take the rotation of both and see if they are within 180' of each other? It's confusing!
because when I was Raycasting, it was selecting the planes that weren't visible to the camera because of the Collider, so I had to do RaycastAll so I have many planes but I just want the ones rotated visible to the camera.
Answer by Paulius-Liekis · Nov 26, 2012 at 04:15 PM
Vector.Dot(plane.tranform.forward, camera.transform.position - plane.tranform.position) > 0
This is assuming that plane.tranform.forward if normal of the plane and that you're using perspective camera (not-orthogonal)
great answer thank you. I figure I can also use camera.transform.forwards for the 2nd vector
Good thinking. But there is one detail: camera.transform.forwards will work only with orthogonal cameras. Think about this case: if plane is on the side of the screen then when Dot product is 0 (i.e. it's perpendicular to the screen) the plane is still visible, because it projection camera (not orthogonal).