Author Topic: Raycast distance of UICamera  (Read 3436 times)

hesoul

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Raycast distance of UICamera
« on: January 03, 2014, 07:38:28 AM »
The distance is calculated:
float dist = (cam.rangeDistance > 0f) ? cam.rangeDistance : currentCamera.farClipPlane - currentCamera.nearClipPlane;
when camera is OrthoGraphic there was no problem,but in 3D camare,whether this should be changed?
float dist = 0;
if (cam.rangeDistance > 0f) dist = cam.rangeDistance;
else
{
    dist = currentCamera.farClipPlane - currentCamera.nearClipPlane;
    if (!currentCamera.isOrthoGraphic)
        dist /= Mathf.Cos(Vector3.Angle(currentCamera.transform.forward, ray.direction) * 0.01745f);
}
« Last Edit: January 03, 2014, 08:52:59 PM by hesoul »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Raycast distance of UICamera
« Reply #1 on: January 03, 2014, 10:05:20 AM »
This means you may hit invisible objects. If you want extended range, set the raycast range on the UICamera.

hesoul

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Raycast distance of UICamera
« Reply #2 on: January 03, 2014, 10:31:40 AM »
but 4 corners may not be hit,as shown in the figure,the red area can not be hit

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Raycast distance of UICamera
« Reply #3 on: January 03, 2014, 11:03:00 AM »
Yup, I know. But in your case objects behind the visible plane will be hit, which is just as wrong. There is no perfect fix here.