How did you switch from Pixel/Frame to Pixels/Second

Hi, am new to coding and physics terminology so this is a very basic question.

In your tutorial Velocity was initially at Pixel/Frame with a value of 1. This changed to Pixels/Second by changing the value to 60. I do not understand how changing the value changes the Velocity output from Pixel/Frame to Pixels/Second.

The same applies in the application of the code, Gravity had a value of (1) and was (pixels/frame)/frame, but as soon as the value was updated to 1000, it became (pixels/second)/frame. How?

Am struggling to understand this conversion which is something probably very basic. If anyone could help or point me towards an article that be great.

We’re changing the values from one to the other by multiplying them by delta time. Which is the time taken between the start of the previous frame and the start of the current frame.

Since delta time is a value that represents time, this takes our calculation from pixels-per-frame to pixels-per-unit-if-time. In our case it’s seconds (but it could be milliseconds or some other representation of time).

As a result, the values used for moving our character (velocity) and gravity in the game world have to be adjusted to also be a value over time. Otherwise, 1 pixel / second is very slow.

In summary. It’s not the value changing that makes it pixels/second, but the fact we’re multiplying that value by the delta time between frames. But as a result we need to change the values so the game runs at a speed that feels good for the game.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms