Search Unity

Is there a way to make up go up, in scene view? (ie. not forward when looking down)

Discussion in 'Editor & General Support' started by Aeroxima, Nov 12, 2019.

  1. Aeroxima

    Aeroxima

    Joined:
    Jul 19, 2016
    Posts:
    15
    I'd love it to be default, or maybe a setting, or at least a script I can use or make.

    I just want it to go up/down in world space when I push those keys in fly mode, rather than relative to the character/view, which is weird and I've never seen anything control that way before. I find it much more annoying.

    I finally learned I can set the speed up (3 is good) and take off easing and acceleration, and it feels WAY nicer (more responsive and immediate). It would be perfect if the up/down keys didn't move the camera at an angle when not looking straight forward. I find myself looking up, adjusting, and looking back down, or moving again after going up/down, and fiddling with it back and forth till it becomes an OCD thing and gets more frustrating than it should, lol.
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    By default, you can use E and Q to go up and down in fly mode. You can change your keys under [Edit -> Preferences -> Keys].
     
  3. Aeroxima

    Aeroxima

    Joined:
    Jul 19, 2016
    Posts:
    15
    Those are what I've been referring to. They only go up and down relative to your view, which means if you're looking up or down, you move forwards and back when you push up and down.

    For example, try looking straight down and push the up key. You don't go up at all. For a more extreme example, look upsidedown, and up goes down, and down goes up.
     
  4. Aeroxima

    Aeroxima

    Joined:
    Jul 19, 2016
    Posts:
    15
    So I've been playing around with SceneView and came up with this:

    Code (CSharp):
    1. using UnityEditor.ShortcutManagement;
    2.  
    3. public class EditorShortCutKeys : ScriptableObject
    4. {
    5.     [Shortcut("3D Viewport/Fly Mode True Up", KeyCode.Space)]
    6.     static void FlyModeTrueUp()
    7.     {
    8.         SceneView view = SceneView.lastActiveSceneView;
    9.         view.pivot += new Vector3(0, 1 * view.cameraSettings.speed, 0);
    10.     }
    11. }
    12.  
    It's janky, but it confirms this is what I would want for sure. The biggest problem is it stops moving a moment when you hold it, because it's a shortcut and the keyboard takes a moment to start repeating.

    Anybody know a better way to do it? Anybody even reading? lol
     
    hjohnsen likes this.
  5. Aeroxima

    Aeroxima

    Joined:
    Jul 19, 2016
    Posts:
    15
    I improved things a lot since before and forgot to post and took a break for a while. I think this is about as good as I'm going to get it without being able to edit Unity's source code.

    Never expected to be getting into this before finishing even a game jam sized game. Some of this stuff is really lacking documentation and took way longer than it should have cause I've been in over my head and had to do some kind of hacky stuff. But it works for practical purposes.

    In case somebody doesn't know how to use it: Just put the file in a folder called "Editor" somewhere in your project, it can be a subfolder of something else, and you'll have new shortcuts you can rebind in Unity. I set the default to Space and Q for this because I doubt many are using what I use (Dvorak's ESDF equivalent).

    Improvements/comments always welcome.

    Edit: Note it doesn't use camera easing or acceleration, I leave them off anyway.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using UnityEditor.ShortcutManagement;
    4.  
    5. #pragma warning disable IDE0051 // Stop messages about unused functions, they are actually used because of Unity attributes
    6.  
    7. //todo: speed isn't rite
    8. //      it speeds up after being held a bit, even when using a flat constant number like 0.2f (not bad actually, small adjustments slower, moving looking downward works better)
    9. //          (still weird though, would like to know why)
    10. //
    11. //cleanup: it recognizes it when holding shift and pressing it, but uses a second shortcut key for it - must be a better way
    12.  
    13. public class TrueUpAndDown
    14. {
    15.     private const float flySpeed = 4.75f;               //kind of just arbitrary, adjusts speed compared to other directions to make them close
    16.     private const float shiftSpeedMod = 5f;             //what unity seems to use for speed when holding shift
    17.     private const float fakeDeltaTime = 0.0102051939f;  //because making it not fake seems like a pain
    18.  
    19.     [ClutchShortcut("3D Viewport/Fly Mode True Up", typeof(SceneView), KeyCode.Space)]      //really lacking documentation on a lot of this stuff
    20.     static void FlyModeTrueUp(ShortcutArguments arguments)
    21.     {
    22.         if ((Tools.viewTool == ViewTool.FPS) && (arguments.stage == ShortcutStage.Begin))
    23.         {
    24.             SceneView.duringSceneGui += MoveUp;
    25.         }
    26.  
    27.         if (arguments.stage == ShortcutStage.End)
    28.         {
    29.             SceneView.duringSceneGui -= MoveUp;
    30.         }
    31.     }
    32.  
    33.     [ClutchShortcut("3D Viewport/Fly Mode True Down", typeof(SceneView), KeyCode.Q)]
    34.     static void FlyModeTrueDown(ShortcutArguments arguments)
    35.     {
    36.         if ((Tools.viewTool == ViewTool.FPS) && (arguments.stage == ShortcutStage.Begin))
    37.         {
    38.             SceneView.duringSceneGui += MoveDown;
    39.         }
    40.  
    41.         if (arguments.stage == ShortcutStage.End)
    42.         {
    43.             SceneView.duringSceneGui -= MoveDown;
    44.         }
    45.     }
    46.  
    47.     //Just calling the others except these catch it when shift is held first
    48.     [ClutchShortcut("3D Viewport/Fly Mode True Up (with shift)", typeof(SceneView), KeyCode.Space, ShortcutModifiers.Shift)]
    49.     static void FlyModeTrueUpWithShift(ShortcutArguments arguments)
    50.     {
    51.         FlyModeTrueUp(arguments);
    52.     }
    53.     [ClutchShortcut("3D Viewport/Fly Mode True Down (with shift)", typeof(SceneView), KeyCode.Q, ShortcutModifiers.Shift)]
    54.     static void FlyModeTrueDownWithShift(ShortcutArguments arguments)
    55.     {
    56.         FlyModeTrueDown(arguments);
    57.     }
    58.  
    59.     static void MoveUp(SceneView view)
    60.     {
    61.         view.pivot += new Vector3(0, OverallSpeedFormula(view), 0);
    62.     }
    63.  
    64.     static void MoveDown(SceneView view)
    65.     {
    66.         view.pivot += new Vector3(0, -1 * OverallSpeedFormula(view), 0);
    67.     }
    68.  
    69.     private static float OverallSpeedFormula(SceneView view)
    70.     {
    71.         if (Event.current.shift)
    72.             return flySpeed * view.cameraSettings.speed * fakeDeltaTime * shiftSpeedMod;
    73.         return flySpeed * view.cameraSettings.speed * fakeDeltaTime;
    74.     }
    75. }
     

    Attached Files:

    Last edited: Aug 1, 2020
    xeosD likes this.
  6. xeosD

    xeosD

    Joined:
    Apr 6, 2023
    Posts:
    9
    Unless you want to hold down a mouse button, no. There are addons in the asset store that make this possible, though.
     
  7. Aeroxima

    Aeroxima

    Joined:
    Jul 19, 2016
    Posts:
    15
    I couldn't find any addons the 2-3 times I looked, but it was hard to know what to search for.

    The one I made works well, I haven't noticed any issues. I thought I made more improvements but the one I have is still the same as what's posted. I'm not sure what my old comment about the speed was about, it doesn't seem to be the case anymore (if it ever was), at least in Unity 2020.3.48f1.

    I thought about releasing it somewhere (free) but I'm not sure where, and it seems like nobody else cares, even though every game I've ever seen has up actually go "global up", not "local up". Besides messing with muscle memory, flying over things while looking down is hard when you have no up key because up partially converted to forwards from looking down.

    Edit: And yeah, I was looking for it to work like other movement keys, only when holding the button (ie. being on the right tool). That was one of the harder parts to figure out because I couldn't find any documentation at all on it, but found what I needed in the Unity source code posted online somewhere and worked from that.

    To make it work anytime would probably be easy, just removing the "(Tools.viewTool == ViewTool.FPS)" part.
     
    Last edited: Sep 11, 2023
  8. xeosD

    xeosD

    Joined:
    Apr 6, 2023
    Posts:
    9