Something like this might work. I really need to be working in Unity to test and fix, but, until then…
var camera : Camera;
function FrustumIntersect(origin : Vector3,targetPos : Vector3) : Vector3
{
viewAngle = Mathf.Deg2Rad*camera.fieldOfView*camera.aspect;
var angleA = Mathf.Deg2Rad*Vector3.Angle(transform.position – origin,targetpos – origin);
var angleB = Mathf.PI() – (viewAngle/2) – angleA;
var distToIntersect = angleB*Mathf.Sin(angleA)/(Vector3.Distance(origin, transform.position));
var intersect : Vector3;
intersect.x = distToIntersect * Mathf.Cos(transform.localEulerAngles.y + viewAngle/2 );
intersect.y=origin.y;
intersect.z = distToIntersect * Mathf.Sin(transform.localEulerAngles.y + viewAngle/2 );
return intersect;
}
This should find an intersect point to the left. The origin parameter is a point that is x units in front of camera (in your OP, you said 10 units, so origin would = transform.position + Vector3.forward*10). If you want to find one to the right, just change:
intersect.x = distToIntersect * Mathf.Cos(transform.localEulerAngles.y + viewAngle/2 );
intersect.y=origin.y;
intersect.z = distToIntersect * Mathf.Sin(transform.localEulerAngles.y + viewAngle/2 );
To:
intersect.x = distToIntersect * Mathf.Cos(transform.localEulerAngles.y - viewAngle/2 );
intersect.y=origin.y;
intersect.z = distToIntersect * Mathf.Sin(transform.localEulerAngles.y - viewAngle/2 );
I have no doubt there is a mathematical way to figure out whether it should be left or right and be able to work that into the function, but until even this bit proves to work, I wouldn’t worry about it.
Try it out. Andeee, if you have a chance, test this out and let me know how it breaks. I won’t be able to test it myself until late, late tonite.
Edit: One thought. I don’t know much about aspect ratio, but I assume an aspect ration of 2:1 would mean that, if a camera is set to 60 degree FOV, then the horizontal FOV would be 120. It’d be nice if it was that simple, but now I’m suspecting it isn’t. If not, then the code won’t work for sure.