1
\$\begingroup\$

I have an object - player - which is moving X px ahead each update (updates based on device FPS). From my results, to get average same player speed on all devices, is to do calculation screenWidth / averageFPS. This should give me speed, that player reaches mobile screen width for one second (note my game is in landscape mode). But it doesn't, it was significaly faster on Z3 Compact (720x1280; avg. 60FPS) than on tablet A5600-F (800 x 1280; avg. 62FPS).

How to get correct speed?

\$\endgroup\$
2
  • \$\begingroup\$ Are you sure screenWidth value is 1280 instead of 720 or 800? Maybe your calculations are right but you're working on wrong values because of landscape mode. Even though, be sure screen size values are updated to the phone view mode. \$\endgroup\$
    – liggiorgio
    Dec 2, 2015 at 22:01
  • \$\begingroup\$ By the way, as @Almo suggest you shouldn't be working in pixel coordinates, neither your game shall depend on device frame rate. Delta time was introduced right to simplify the programming aspect of games dynamics. Game physics must always be independent from drawing the game view. \$\endgroup\$
    – liggiorgio
    Dec 2, 2015 at 22:04

1 Answer 1

1
\$\begingroup\$

You should be working in world coordinates, not pixel coordinates.

For example, in a Unity project, I might have a world 100 units across, and the speed is 1 unit per second. It takes 100 seconds to cross the screen. The engine takes care of worrying how many pixels per frame that is.

On a related note, you don't move a certain distance per frame. You check the "delta time" of the current frame, and adjust the speed for how long the frame takes in order to keep the speed consistent regardless of the frame rate.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .