- Home /
Setting to Show Camera Cone Always?
When a camera is selected, it's cone becomes visible in the viewport. When a different camera is selected, it's cone becomes visible and the first camera's cone disappears.
Is there a setting anywhere to show a camera's cone in the viewports all the time?
Thanks!
I would also really like to be able to do this, since I otherwise have to awkwardly click the camera, check the field of view, move some other object, then click the camera again to gauge position relative to the camera view.
This makes it especially difficult to position objects out of the camera view with a buffer.
$$anonymous$$ay I suggest you add the word Frustum to your title (technical word for the camera pyramid), for future searchers.
Answer by Glurth · Dec 31, 2016 at 11:00 PM
I don't know of a way to do this by default.
However, if you add this script to a scene object, and drag over it's single field, the camera you want to see the frustum for, it will ALWAYS draw the frustum (unless you specifically disable the object or script).
using UnityEngine;
[ExecuteInEditMode]
public class FrustumAlways : MonoBehaviour {
public Camera cameraShowFrustumAlways;
private void OnDrawGizmos()
{
if (cameraShowFrustumAlways)
{
Gizmos.matrix = cameraShowFrustumAlways.transform.localToWorldMatrix;
Gizmos.DrawFrustum(cameraShowFrustumAlways.transform.position,
cameraShowFrustumAlways.fieldOfView,
cameraShowFrustumAlways.farClipPlane,
cameraShowFrustumAlways.nearClipPlane,
cameraShowFrustumAlways.aspect);
}
}
}
Sorry but I have a Network problem, I was making a game but I need to Sync betwen host and client a simple spotlight state (enabled/disabled; intensity; color, etc...) I was surfing the web for hours and found nothing please help!
$$anonymous$$ay I suggest you create a new question for that @Grench1 (with lots of details) This question appears unrelated to that.
Yea I did yesterday in the morning but stills in moderation :(
EDIT: Gizmos.DrawFrustum()
has a subtle bug, hence the script doesn't work as expected: The "apex" is in fact the near plane center.
Here's the modified script to account for the bug:
using UnityEngine;
[ExecuteInEdit$$anonymous$$ode]
public class FrustumAlways : $$anonymous$$onoBehaviour {
public Camera cameraShowFrustumAlways;
private void OnDrawGizmos()
{
if (cameraShowFrustumAlways)
{
Gizmos.matrix = cameraShowFrustumAlways.transform.localToWorld$$anonymous$$atrix;
Gizmos.DrawFrustum(new Vector3(0, 0, cameraShowFrustumAlways.nearClipPlane),
cameraShowFrustumAlways.fieldOfView,
cameraShowFrustumAlways.farClipPlane,
cameraShowFrustumAlways.nearClipPlane,
cameraShowFrustumAlways.aspect);
}
}
}
This is so good that Unity should have it built-in. This is why:
Normally how can you "visually aware" move an object in and out of the frustum of a camera? 1. You see it in the game view. But if you have problematic objects like very transparent or too small: 2. you should use the Scene view - it has wireframe plus you can move the objects and you see them while moving ;) So, you align view to camera and see them. But the Scene view, although aligned, doesn't have the very same frustum as the Game view. Plus you can't always view both at the same time: the moving object and the aligned view. The only viable way w/o being ghetto is: 3. You have the frustum always displayed while you move the objects about.
"The "apex" is in fact the near plane center." Oh gosh, that's confusing! nice catch.
Hmm, I see you are using a model-space coordinate for the first param, but I used the worldspace.position- was that wrong too (haven't tested it in a while)?
Yes :D and the apex is exactly what you and I thought it was (and surely what the coder of the method thought) - it's just the method definition that's flawed.
Your answer
Follow this Question
Related Questions
How to render severals cameras at differents Frame Rate ? 2 Answers
Android hortographic camera cropping 1 Answer
Implement fog settings independent of the Scene Render settings. 4 Answers
Camera cone 2 Answers
When to use pixel perfect camera in 2D? 0 Answers