Hello, when the camera moves, the sprites of my objects shake:

If I use this code inside my camera, which should help to get the pixel perfect, the shakes stop.
public static float RoundToNearestPixel(float unityUnits, Camera viewingCamera)
{
float valueInPixels = (Screen.height / (viewingCamera.orthographicSize * 2)) * unityUnits;
valueInPixels = Mathf.Round(valueInPixels);
float adjustedUnityUnits = valueInPixels / (Screen.height / (viewingCamera.orthographicSize * 2));
return adjustedUnityUnits;
}
void LateUpdate()
{
Vector3 newPos = transform.position;
Vector3 roundPos = new Vector3(RoundToNearestPixel(newPos.x, _mainCamera), RoundToNearestPixel(newPos.y, _mainCamera), newPos.z);
transform.position = roundPos;
}
The problem is that if I turn VSync off, the camera stutters and stop to work properly (only with the stand alond version):
VSync On:

VSync Off:

Anyone can help me pls?
This is the rest of the code of the camera:
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour
{
private Transform _player;
private Camera _mainCamera;
private OptionsManager _optionsManager;
private Vector2 _mousePos;
private Vector2 _playerPos;
private Vector2 _newPos;
private float _dist;
private float _maxDist = 4f;
float x, y;
public Vector2 smoothing = new Vector2(5f, 5f);
[HideInInspector]
public bool isCameraLocked;
void Start()
{
_mainCamera = GetComponent<Camera>();
_optionsManager = GameObject.FindGameObjectWithTag("MainMenuManager").GetComponent<OptionsManager>();
UpdateOrthographicSize(_optionsManager.cameraScale);
_player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
if (_player != null)
transform.position = new Vector3(_player.position.x, _player.position.y, transform.position.z);
}
void Update()
{
if (isCameraLocked == false)
{
_mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
_playerPos = new Vector2(_player.position.x, _player.position.y);
_newPos = _playerPos + ((_mousePos - _playerPos) / 2);
x = Mathf.Lerp(transform.position.x, _newPos.x, smoothing.x * Time.deltaTime);
y = Mathf.Lerp(transform.position.y, _newPos.y, smoothing.y * Time.deltaTime);
transform.position = new Vector3(x, y, transform.position.z);
}
}
public void UpdateOrthographicSize(int scaleIndex)
{
// OrthographicSize = Screen resolution height / PPU * Scale (32x8 o 32x4);
float screenHeight = Screen.height;
int scale;
if (scaleIndex == 0)
scale = 4;
else
scale = 8;
_mainCamera.orthographicSize = screenHeight / (32 * scale);
}
public static float RoundToNearestPixel(float unityUnits, Camera viewingCamera)
{
float valueInPixels = (Screen.height / (viewingCamera.orthographicSize * 2)) * unityUnits;
valueInPixels = Mathf.Round(valueInPixels);
float adjustedUnityUnits = valueInPixels / (Screen.height / (viewingCamera.orthographicSize * 2));
return adjustedUnityUnits;
}
void LateUpdate()
{
Vector3 newPos = transform.position;
Vector3 roundPos = new Vector3(RoundToNearestPixel(newPos.x, _mainCamera), RoundToNearestPixel(newPos.y, _mainCamera), newPos.z);
transform.position = roundPos;
}
public void UpdatePlayer(Transform playerTransform)
{
_player = playerTransform;
transform.position = new Vector3(_player.position.x, _player.position.y, transform.position.z);
}
public void UpdatePlayer()
{
_player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
transform.position = new Vector3(_player.position.x, _player.position.y, transform.position.z);
}
}
I have also a question about the refresh rate of the monitors please.
I have an Asus monitor which could run at 144Hz, but Unity doesn’t show these resolution when I use Screen.resolutions, it shows few 60Hz, many 59Hz and one at 75Hz. Why is that?
Thanks a lot.