Getting position where raycast goes offscreen

Is it possible to fire a raycast in a direction, then get the position when the raycast hit the edge of the screen in world coordinates? For example -

alt text

Let's say this is a 2d game and the black circle is the player. He fires off raycasts in arbitrary directions (the blue rays). Can we get the position where the ray left the camera viewport? Apologies if I'm missing something simple here(which is likely).

You can get the Camera Frustum planes by using the GeometryUtility.CalculateFrustumPlanes() function built into Unity. This function returns an Array of planes that make up the viewport. You can then use the algorithms on this page to determine where the intersection happened.

This should be faster to calculate than using colliders, and doesn't need to involve the physics engine at all.

I'm not exactly sure what you're asking. However, it seems to me that you want to find the position that the players bullet left the area you can view. One way to accomplish this is to create four box colliders. Arrange them around the edges of the screen and make them children of the camera. Then, using Raycast.Hit, you can find the positions at which they 'left the screen'. In other words, where they hit the colliders arranged around the edges of the screen. You can then use hit.point like this:

var hit : RaycastHit;
var edgeOfScreenHit;

function Update () {
    if (Physics.Raycast (ray, hit)) {
        edgeOfScreenHit = hit.point;                    

Hope this helps!