Movements changing over resolutions

Hi,

I am developing an Android game at the moment and I have started doing some tests on different devices. At first I believed that this was a viewport issue but upon returning to the Editor for some more tests I have come across this issue.

The x component should be in a multiple of 1280 and using the 16:10 Landscape preset, this is true. Across other presets however it changes.

For example

48822-3.png
48823-4.png

Also, the Z keeps changing but this isnt a problem :stuck_out_tongue:

This is the code that handles the movement of the object in question

CharacterCreation.transform.position = new Vector3(Mathf.Lerp(CharacterCreation.transform.position.x, (-characterIndex * 1300), Time.deltaTime * 5), 0, 0);
             
            if (CharacterCreation.transform.position.x <= (-characterIndex * 1280) && goNext)
            {
                CharacterCreation.transform.position = new Vector3(-characterIndex * 1280, 0, 0);
                Debug.Log(CharacterCreation.transform.position);
                isTransationing = false;
            }
            else if (CharacterCreation.transform.position.x >= (-characterIndex * 1280) && !goNext)
            {
                CharacterCreation.transform.position = new Vector3(-characterIndex * 1280, 0, 0);
                Debug.Log(CharacterCreation.transform.position);
                isTransationing = false;
            }
            groundtempthing.transform.position = new Vector3(Camera.main.transform.position.x, -95, 0);

It says 1300 in the first line to get it over the 1280 multiple threshold, otherwise it never reaches it for some reason.

Anyway, just to reiterate,

  • Moving an object in multiples of 1280
  • Doing so at 16:10 Landscape moves it correctly
  • Doing so at any lower ratio or resolution causes it to fall short or over shoot

If I have missed anything that might help you help me, let me know, thanks :slight_smile:

I recommend you to use Screen.width and Screen.height instead of constant values. You can read about it there. Android devices has A LOT OF DIFFERENT RESOLUTIONS.

Instead of constant 1280, 1300 like values, you must implement special formulas that will find the coordinates proportial to your screen size.

Also there is lazy variant. You can set strict resolution. So in all devices it will have only one resolution. However, in some devices with different aspect, it could look very ugly.