Different velocity on mobile devices using 2D Physics

We’re working on a simple physics game that involves bouncing a ball off of a paddle. We set the velocity of the ball so that it stays constant. Problem is that when we deploy the build onto various mobile devices the ball moves at different speeds across the different devices. This is all done in 2D. The objects use rect transforms and rigidbody2D components. We have tried various methods of compensating for different screen sizes and densities, but none have worked. For example, we tried multiplying our velocity by (Screen.width / GetComponent().referenceResolution.x) which has solved other screen size issues for us, but did not work for creating a consistent speed across devices. Any help?

UPDATE: We figured out that the appearance of different speeds was caused by the lower-end devices lagging. The lag on those devices ends up causing everything to move slower than expected. I would have expected the physics engine to compensate and cause some frame loss, not reduce speed. The problem was further obscured by our attempts to compensate for delta-time and dimension which appears to be unneeded.

Unity will execute more than one FixedUpdate if it’s required because of extreme lag which will cause everything based on fixed-update (including 2D/3D physics systems and fixed-update calls to MonoBehaviour scripts) to catch-up. The physics simulations won’t change as they only see a time-slice related to a fixed-update; it’s just that because of the lag you’re seeing, the fixed-updates won’t be called at regular intervals.

1 Like

I’m seeing a similar problem. Currently I’m updating my objects velocity in Update(). Everything works fine in the editor, but on different devices I get different results. Should I move that code to FixedUpdate? Should I abandon using physics and simply adjust the transform?

Edit: Got it, I changed the code to update the velocities to FixedUpdate and now the devices match the editor.