Updating Frames Per Second

According to Unity, the Update function is called every frame. And if we render a set amount per second, then in theory, that should be the amount of times Update is called per second.

Why is this important? Because, as computers get faster and more powerful, Unity is able to render more FPS, and as FPS gets larger, the Update function is called more often.

If Update function is called more frequently, wouldn’t this be a good thing? Not necessarily, especially if the code is being reset every time the Update function is called. As a result, a player who has a recently built computer will not have the same experience as someone who might have a computer that’s a couple of years old.

A Controlled Logic

In this example, we are trying to move the player left and right while allowing them to jump. We are changing the y value whenever the player presses the Spacebar because the character is jumping.

However, if we don’t cap the FPS, this is what we get:

Even though we are pressing the Spacebar, it doesn’t look like the character is jumping. This could be because we are setting the character’s position back to 0 at the start of the Update function.

Limiting the FPS

If we want players to have similar experience with our game, we might have to limit the FPS. Just by adding this line of code in the Start method, we can limit the FPS to any number we want:

Application.targetFrameRate = 30;

By limiting the FPS to 30 instead, this is the result we get:

Character jumping with a limit of 30 FPS

And if we were to increase the FPS limit, we get to see a jump that is closer to the ground:

Character jumping with a limit of 60 FPS
Character jumping with a limit of 120 FPS
Character jumping with a limit of 240 FPS




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How I won Nephack Online CTF 2020

PVS-Studio 7.18: updates and enhancements

Event Streaming (Apache Kafka): Integrate Your E-Commerce Platform

Active ssh-tunnel

The best reason to use DynamoDB streams is…

Managing Ignorance & JIT Learning

Launch WordPress on EC2 instances by using RDS and MySQL

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Josh Vang

Josh Vang

More from Medium

How to obtain Test TRBs  (and bridge it over to Mumbai)

Programed or be programed. How long will we let tech define us?

The Client: Ukraine. The Brief: Prevent World War III

The Numbers Don’t Add Up