Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Isometric movement seems faster horizontally

Discussion in 'Scripting' started by pixldev, Jul 1, 2022.

  1. pixldev

    pixldev

    Joined:
    Nov 6, 2019
    Posts:
    13
    I have an orthographic camera with (30, 45, 0) rotation. The problem is that the player seems to move faster left or right than up or down. Maybe I could divide the horizontal velocity? I don't know by how much though.
     
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Let's first figure out if he's actually moving faster or it just seems that way, can you view the player speed at run time?

    What's the game and what's your movement code?
     
  3. pixldev

    pixldev

    Joined:
    Nov 6, 2019
    Posts:
    13
    I've just checked and the player moves with equal speed in all directions. The movement also looks fine in a perspective camera. So it's not really faster, it just looks that way.

    There is an isometric camera and the player moves with WASD. The movement code:
    Code (CSharp):
    1. public class PlayerController : MonoBehaviour
    2. {
    3.     [SerializeField] CharacterController charController;
    4.     [SerializeField] float speed;
    5.  
    6.     Vector2 input;
    7.  
    8.     void OnMove(InputValue value)
    9.     {
    10.         input = value.Get<Vector2>();
    11.     }
    12.  
    13.     void Update()
    14.     {
    15.         var move = new Vector3(input.x, 0f, input.y);
    16.  
    17.         var matrix = Matrix4x4.Rotate(Quaternion.Euler(0f, 45f, 0f));
    18.         move = matrix.MultiplyPoint3x4(move);
    19.  
    20.         charController.Move(move * speed * Time.deltaTime);
    21.  
    22.         if (move != Vector3.zero)
    23.         {
    24.             transform.rotation = Quaternion.LookRotation(move);
    25.         }
    26.     }
    27. }
     
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Really?, how did you check?
    Because looking at your code you're gonna have the problem that you move diagonally faster than just horizontally or vertically, you need to normalize the "move" vector.
     
  5. pixldev

    pixldev

    Joined:
    Nov 6, 2019
    Posts:
    13
    I logged the character controller velocity in Update() :) It is a problem with how the isometric camera sees things because the speed looks fine in the perspective one.

    That's not the issue, the input is normalized in the input system.

    I made a video:
     
  6. iMobCoding

    iMobCoding

    Joined:
    Feb 13, 2017
    Posts:
    161
  7. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    530
    That's how geometry works. If you move at constant speed in 3d space, then for orthographic camera at angle movement relative to screen will be slower in vertical direction.

    There are two simple ways you can convince yourself about it. Draw axis parallel square on the ground. You will see that one diagonal is much longer than the other one. So traveling on both diagonals is same distance 3d space (because it is a square) but for camera one of the directions looks compressed and as a result slower speed.


    Slightly different way you can think about it is by considering what happens in the edge cases. If the orthogonal camera was fabing straight down like a topdown camer (let's call it 0 degrees angle) movement in both direction will look like they have same speed. If camera where facing horizontally (90 degrees) movement sideways will still have the same speed, but movement "up and down" will result in movment into and out of the screen, but since there is no perspective it will look like nothing happens. At 89 degrees "up and down" will still result mostly in into/out of screen movement but with slight movement up and down relative to screen. Closer the camera angle is to 0 degrees facing downward the bigger portion of 3d movement will happen relative to vertical screen axis.


    If you apply little bit of basic high school math you can calculate the at the vertical movement relative to screen will be
    cos(angle)
    of the movment in 3d space along the corresponding axis. If you want constant movement speed in screen space instead of constant speed in 3d space you will need to divide the movement along the corresponding axis by that. In your case probably cos(30) or cos(90-30) depending on whether 0 degrees is considered fully vertical or fully horizontal.

    Whether you should compensate for the camera angle and adjust the movement speed so that it's constant in screen space will depend on your game design choices. Plenty of isometric games use constant movement speed in 3d space, and there are also plenty that have constant speed in screen space (often because they are actually 2d games using isometric sprites and that's the easier to do instead of intentional choice). If you have constant speed in screen space that may result in some weirdness which can have impact on gameplay. If you allow rotating camera around vertical axis it will be possible to increase travel speed across level by strategically changing camera angle which would be somewhat weird. There some games like fez which intentionally take this effect to extreme as puzzle game mechanic. Another weirdness will come if you have something like circular area effects happening (which look like ellipsis in orthographic camera) . The player will be able to run to the edge of circle and dodge the effect in vertical direction faster than horizontal one.

    Slightly different approach which avoids the visual movement speed differences is having main movement directions match with 3d world axes (diagonal in screen space). This may seem slightly weird but depending of the level design most of the walls and most common walking direction can be diagonal anyway, making it less weird. Whether diagonal movement is a problem will depend on the style of game. It might be more of a problem for more action oriented games, less of problem in slower pace puzzle games. But in case of something like platforming where you have to jump across a gap having movement aligned with axis of level geometry might even make things easier.


    As for why it's not a problem with perspective camera. I can't tell for sure. Part of the geometrical effects and reasoning still apply. I think it's just we are so used to looking at things with perspective in real world that our brains perceive it differently and compensates for it. Just like those illusions where things look darker in the shadow even though they are the same pixel color in image.