Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ALEXALEX303 · Jul 18, 2014 at 09:11 PM · newframe rateargumentdependencyexplanation

Framerate Dependency

Hey UnityAnswers,

I'm making a very simple 2D side-scroller for the learning experience. It does not use gravity or any other physics, the character just moves to the right. I keep reading about framerate dependacy and fixedupdate and what not and after reading a couple of UnityAnswers questions some of them seem to be contradictory(no offense).

Most people say that if you say FixedUpdate for your movement it's already frame rate independent and using DeltaTime is useless.

This is the code I have at the moment for my very basic movement: function FixedUpdate() { rigidbody2D.velocity = transform.right * 3; }

Will it function the same regardless of framerates? Please provide arguments and/or examples to help me understand.

Thank you in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Kiwasi · Jul 18, 2014 at 11:03 PM

FixedUpdate runs at a fixed framerate, so it appears to be framerate independent. However there are many circumstances where you will want to change the physics framerate. Using Time.deltaTime will also make your calculations easier, as you will be working in per seconds instead of per fixedupdate frame. It also means there are no strange behaviours if you change your physics frame rate at a later stage.

Time.deltaTime will return according to the framerate of whichever update cycle you call it in. If you are in fixedupdate it will return the delta time from the last physics update, in update it returns the delta time from the last update cycle.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ComedicAutomaton · Nov 09, 2016 at 11:39 PM 0
Share

From the definition of FixedUpdate() not sure how it is frame rate independent. If it's called X number of times per frame that makes it frame rate dependent.

avatar image Bunny83 ComedicAutomaton · Nov 10, 2016 at 01:28 AM 0
Share

It is framerate independent. It is not called X number of times per frame but X number of times per second. By default the fixedDeltaTime is set to 0.02 seconds which makes FixedUpdate run exactly 50 times per second regardless of the visual framerate.

What makes the concept of FixedUpdate a bit hard to understand is the "realtime spacing" between FixedUpdate calls might not be equally, however that doesn't matter for physics since all we need is a constant call rate per second.

avatar image
0

Answer by Saad_Khawaja · Jul 18, 2014 at 10:46 PM

Your code is not framerate/timescale independent yet.

Googled this answer for you:

Time.deltatime (duration of last frame) should only be used in once per frame calls e.g. Update() calls. Time.fixedDeltaTime should only be used in FixedUpdate(), since it the sample time of the physics loop.

The physics loop is called a fixed number of times per second (constant fixedDeltaTime) and Update is called a variable number of times per second (a non-fixed deltaTime). So, yes, you make calculations time independent in the Update-call and the FixedUpdate() by using Time.deltaTime and Time.fixedDeltaTime, respectively.


Edit: Just checked, Time.fixedDeltaTime returned 0.02 so that means FixedUpdate is called after every 0.02 seconds. You need to multiply with this variable to make sure that once you change timescale, your speed is constant.

Otherwise, it always gives the same number so you may/may not use it in your calculations. Your frame rate will be independent.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kiwasi · Jul 18, 2014 at 11:04 PM 0
Share

Check out the docs. No problem using Time.deltaTime in FixedUpdate. Reading Time.fixedDeltaTime is specifically warned against.

avatar image Saad_Khawaja · Jul 18, 2014 at 11:16 PM 0
Share

It is not warned against. If you are inside the FixedUpdate function, there is no difference between Time.deltaTime and Time.fixedDeltaTime.

Time.deltaTime is only recommended because it works on both Update and FixedUpdate. So if you know you're in FixedUpdate like the OP, I don't see any problem in using Time.fixedDeltaTime

avatar image Kiwasi · Jul 18, 2014 at 11:27 PM 0
Share

Except three months down the track when you decide you want it in Update after all. Using Time.deltaTime will work in both settings.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

When Unity3D finally supports WebGL? 2 Answers

Incrimenting a variable when in a certain area 1 Answer

error with learning script 2 Answers

How can I instantiate an object without using Unity? 1 Answer

how can i auto target Gameobject on startup 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges