Movement speed changes based on screen resolution

I’m working on a project where an object will move to a new location when a function is called, and it will move back to its original location when the function is called again. To do this, I’m employing a simple Vector2.MoveToward(), as you can see here:

transform.position = Vector2.MoveTowards(_startPosition.position, _centerPosition.position, _moveSpeed);

It works as intended, but the objects move at different speeds based on the screen resolution. For example, when it is set to Full HD (1920x1080), it moves much faster than it does when its set to 4K UHD (3840x2160).

Is this just because of the amount of pixels its having to cross? Is there a way to normalize the travel time between the different resolutions?

1 Like

If I had to guess, the frame rate probably drops at higher resolutions and your code is t frame rate independent. Multiply _moveSpeed with Time.deltaTime and see if that helps.

1 Like

I tried multiplying _moveSpeed by Time.deltaTime and now they don’t move at all. I also tried using FixedUpdate instead of Update, and that brought the movement to a super slow pace and didn’t fix the difference between resolutions (it also does not move when I include Time.deltaTime).

You will need much higher values of _moveSpeed after you multiply by Time.deltaTime (like a 100 times higher).

1 Like

Ah, I see. I increased the value of _moveSpeed from 1 to 300 and that made them move again. Unfortunately, there is still a clear difference in how long it takes them to move from one location to another between the different screen resolutions.

I found a solution. In addition to multiplying by Time.deltaTime, I also multiplied the _moveSpeed variable by Screen.width. Now everything appears to be moving the same speed no matter the resolution of the screen. Just as a note for anyone who may have this issue - I had to make my _moveSpeed variable much lower after multiplying by Screen.width. It went from 300 to 0.5 to get it to feel right.

1 Like

Just to let you know mate (dyntragos) you are a legend that fix worked.

1 Like

Ty this post saved me