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

RxSwift — Coordinator Pattern done right™

How to generate a EAN-8 barcode as a PNG file in Salesforce Apex

Grid vs Flexbox for CSS

Python影像辨識學習筆記目錄

Where Serverless plugin stops and platform starts

A Simple Guide to Integrating with NetSuite

Setting up your PLEX Server on Raspberry Pi 4

Compilation and Execution of Java Program

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 Does Uniswap Works?

Hello from the Crooked Hill Ranch!

Copa America Top Scorers All Time: Who is the best goalscorer in Copa America?

2021/22 mid-season review: FC Baník Ostrava