Viewport boundaries

How do i get the boundaries of a Camera Viewport at some arbitrary distance from the camera ?

I want to do a 3D ball that bounces with the camera borders no matter what distance to the camera it is…

And taking in mind that the far and near clip planes are variables as well as the field of view

I am doing some tests with raycasts and a collision panel perpendicular to the camera… but is there an easy way ?

Omar Rojo

ScreenPointToRay(Vector3(0,0,0)).GetPoint(dist);

That will get the bottom left corner dist units away from the camera. For the other corners, use Vector3(1,1,0) (top right), and so on.

However, with regard to your overall purpose, you should use 4 box colliders that maintain their distance from the camera with the ball, AND rotate with the camera. So for that, you’ll want to use the middle-of-screen coordinates like (0.5,0,0) for the bottom middle. Further, you’ll need to keep their rotation equal to that of the camera, and you need to ensure that they are always big enough to cover the edge of the screen. (You can get the distance betwee two corners and set the boxcollider’s height to that).

Yeah, i used that function but the problem is that to get the distance from the camera to the object (supposing it is in the middle of the screen) is different that the distance to the ray at one corner since the angles of the vectors pointing to the object and to the corner are different. Should i use regular geometry to calculate the correct distance for the corner that get to the plane in which the object is ?

Did i explain myself right ?

Omar Rojo

Assuming you only need the one object to bounce, that shouldn’t be an issue - by the time it reaches the edge it should be close enough to the correct distance that it bounces anyway… I think?

Well depends on the size of the object… im just taking the geometry center, not plaining to get the closest triangle of the mesh to the border

:confused:

Omar Rojo