- Home /
DrawFrustum not the same as camera
Hi,
I've been trying to draw a frustrum of a camera point. I've been using Gizmos.DrawFrustrum(...)
yet for some reason it doesn't match the gizmo of the camera. I can't find what I'm doing wrong, so hopefully someone here knows.
Here's my code:
Gizmos.matrix = Matrix4x4.TRS(
Camera.main.transform.position,
Camera.main.transform.rotation,
Vector3.one);
Gizmos.DrawFrustum(
Vector3.zero,
Camera.main.fieldOfView,
Camera.main.farClipPlane,
Camera.main.nearClipPlane,
Camera.main.aspect );
And this is what it looks like:
If I change the aspect ratio of the camera, the frustum does not change. For some reason the Camera.main.aspect is always 1.3333
and I don't have a clue why.
Any help would be appreciated!
Thanks
Are you sure your code isn't picking up the Scene View camera? Try to extend the Scene window and see if 1.333 changes.
I'm sure. I tried changing the scene view. Also, my scene and game view are both docked in the same window ( http://i.imgur.com/wFAoYvU.png ), so changing one changes the other. But nope, that's not the problem. I did notice that when I use Camera.current, ins$$anonymous$$d of Camera.main, it does change the aspect, since then it uses the scene camera. Also, when I disable my main camera (the only one in the scene) I get a null error in my frustum drawing script, since then Camera.main doesn't exist anymore. So by that I'm pretty sure it's accessing the right camera.
Are those the only variables that can be pulled from your camera? Seems like it might be missing something small that would cause a wider view.
Try to store the camera in a variable, so you don't get this error. Also, don't expect the gizmos to fully line up. I had this problem once too, when the gizmos didn't quite line up to the camera frustrum, and I solved it by calculating the frustrum manually via trigonometry.
I'm trying to do the exact same thing and I get the exact same error.
Answer by AtticusMarkane · Feb 04, 2015 at 08:33 AM
There are a couple of other threads that people have replied with solutions for drawing it yourself. It would just be nice if this was a silly gotcha that was easy to get around.
Here is a link to one such solution for the next guy that comes around: http://forum.unity3d.com/threads/drawfrustum-is-drawing-incorrectly.208081/