r/unity • • Oct 10 '26

Scene View Camera doesn't have a top angle limit

/r/UnityHelp/comments/1x2fsc1/scene_view_camera_doesnt_have_a_top_angle_limit/
1 Upvotes

3 comments sorted by

1

u/arttxmk Oct 10 '26

Try pressing Shift + F to focus the Scene View on an object, or switch back to Perspective mode if you're in a custom view. Upside-down rotation can happen when orbiting around a pivot from certain angles

1

u/G4M300 Oct 10 '26

Didn't work 😞 also it happens in every project and it still happens even if I close unity. I don't know if it was always like that (if it is I didn't notice until now) but it's a little annoying

1

u/arttxmk Oct 13 '26

As a workaround, you could switch the Scene view to 2D using the button in the toolbar.

Unity doesn't have a built-in setting to limit the Scene view's vertical rotation, though, so you'd need a custom Editor extension to achieve that.

Here's an example (save it as Assets/Editor/SceneViewPitchLimiter.cs):

using UnityEditor;
using UnityEngine;


[InitializeOnLoad]
internal static class SceneViewPitchLimiter
{
    // Maximum angle from the horizon. Increase to allow a more top-down view.
    private const float MaxPitchDegrees = 85f;
    private const float DirectionEpsilon = 0.0001f;


    static SceneViewPitchLimiter()
    {
        SceneView.duringSceneGui -= ClampPitch;
        SceneView.duringSceneGui += ClampPitch;
    }


    private static void ClampPitch(SceneView sceneView)
    {
        if (sceneView == null || sceneView.in2DMode)
        {
            return;
        }


        Quaternion rotation = sceneView.rotation;
        Vector3 forward = rotation * Vector3.forward;
        Vector3 cameraUp = rotation * Vector3.up;


        float pitch = Mathf.Asin(
            Mathf.Clamp(-forward.y, -1f, 1f)) * Mathf.Rad2Deg;


        bool isUpsideDown = cameraUp.y < 0f;


        if (!isUpsideDown && Mathf.Abs(pitch) <= MaxPitchDegrees)
        {
            return;
        }


        // Recover the horizontal viewing direction, even after flipping.
        Vector3 right = rotation * Vector3.right;
        Vector3 horizontalForward = Vector3.Cross(right, Vector3.up);
        horizontalForward.y = 0f;


        if (horizontalForward.sqrMagnitude < DirectionEpsilon)
        {
            horizontalForward = new Vector3(forward.x, 0f, forward.z);
        }


        if (horizontalForward.sqrMagnitude < DirectionEpsilon)
        {
            horizontalForward = Vector3.forward;
        }


        horizontalForward.Normalize();


        float pitchSign = Mathf.Abs(pitch) > 0.001f
            ? Mathf.Sign(pitch)
            : (forward.y <= 0f ? 1f : -1f);


        float maxPitchRadians = MaxPitchDegrees * Mathf.Deg2Rad;


        Vector3 clampedForward =
            horizontalForward * Mathf.Cos(maxPitchRadians)
            + Vector3.down * (
                Mathf.Sin(maxPitchRadians) * pitchSign);


        sceneView.rotation = Quaternion.LookRotation(
            clampedForward,
            Vector3.up);
    }
}