Editor issue: Mouse drag rotation jumps when screen edge wrapping

Hi. I have had an issue for a little while now that’s becoming increasingly frustrating. Does anyone have any thoughts that may help me resolve it?

When navigating through the editor’s sceneview, dragging with the right mouse button rotates the camera. When the mouse is moved to the edge of the screen, it wraps to the other side, allowing the user to continue the camera rotation.

On my home PC, the sceneview camera often randomly jumps in rotation while wrapping. This happens about half of the time, isn’t affected by mouse speed and occurs when wrapping from any edge of the screen. The jump seems to be a random number of degrees too.

I am working in Unity 4.3.0f4 on a windows 8.1 with two monitors. I’ve tried unplugging one of the monitors, but the issue still occurs.

Thanks for any help that you can provide.

bump

Let me know if I bump this too frequently. I’m not so experienced with forums.

bump

Anyone? Am I the only one with this issue?

It still happens from time to time. I hold down Alt and use the Left Mouse Button to orbit the game object in the Scene and when the mouse reaches the corner of my Display, it jumps by 180 degree sometimes… not always. (ver 4.3.3f1)

@IzzySoft: How frequently does this happen to you? It happens to me a little less than half of the time.

It also happens on my editor, does anyone have a solution for this?

I’ve been having this issue on and off for years - Finally got annoyed enough and tracked it down to the delta for the MouseDrag and it’s preceeding Layout events being off by the screen width or height sometimes when the cursor is wrapped.

Setting the delta in the event to something regular when it appears too large eliminates the camera issue for me.

The same issue can occur with any drag event that wraps, so for UI stuff you might need to also adjust the delta for Layout events (I’ve only tested with the camera since it’s easy to see the jump when it happens).

Here’s the code I’ve used as a workaround incase it’s been plaguing anyone else:

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class DragFix
{
    private static int displayWidth;
    private static int displayHeight;
    static DragFix()
    {
        displayWidth = Screen.currentResolution.width;
        displayHeight = Screen.currentResolution.height;
        SceneView.duringSceneGui += OnSceneGUI;
    }
    static void OnSceneGUI( SceneView SceneView )
    {
        if( Event.current.type == EventType.MouseDrag /* || Event.current.type == EventType.Layout*/)
        {
            if( Event.current.delta.y > displayHeight*0.9 )
            {
                Event.current.delta = new Vector2(Event.current.delta.x, Event.current.delta.y - displayHeight);
            }
            else if( Event.current.delta.y < -displayHeight * 0.9 )
            {
                Event.current.delta = new Vector2(Event.current.delta.x, Event.current.delta.y + displayHeight);
            }
            if( Event.current.delta.x > displayWidth * 0.9 )
            {
                Event.current.delta = new Vector2(Event.current.delta.x - displayWidth, Event.current.delta.y);
            }
            else if( Event.current.delta.x < -displayWidth * 0.9 )
            {
                Event.current.delta = new Vector2(Event.current.delta.x + displayWidth, Event.current.delta.y);
            }
        }
    }
}

I know it’s a kind of necroposting, but where do I put this script? Root of the project? Do I have to attach it somewhere (maybe a object in editor)?