Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 SirMacJefferson · Jul 30, 2011 at 04:55 AM · physicsframerateframe

How do you find Unity's frames/second?

I wanted to use Unity to create a small demo for a game I'd been designing, simply to test out the physics, but all of the physics-related writing I have done (movement speed, jumping height, etc.) are done in frames/second. I don't know Unity's framerate. I'm used to 2D games where you can set it. I'd planned on having the FPS set to 30, so all of my "Update()" code would run 30 times per second. I understand the "Time.deltaTime" use, but I don't really want to rely on it. I want to use frames like I have everything written in my game's design document. So can you specifically set a framerate, and if so, where/how do you do such a thing?

Also, I'd planned on using my in-game units as inches, but I also don't know how much Unity moves with "transform.Translate". Does it move 1 pixel if I use "transform.Translate(1,0,0)"? Or is it using some different measurement? Clarification would help a lot!

Thanks!

Comment
Add comment · Show 1
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 Dreamblur · Jul 30, 2011 at 04:58 AM 0
Share

Physics should be handled in FixedUpdate(), not Update(). FixedUpdate() runs synched to time, while Update() only runs every frame.

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Joshua · Jul 30, 2011 at 05:04 AM

The first result in a search for 'Unity3d fixed framerate' already answers your question perfectly, I realize you're new to this site but in the future please use the search function.

What you want to use here is Application.targetFrameRate. I don't advice doing this however, as it's far from a hundred percent reliable and means lag does not only affect how the game is 'perceived' but also how it's actually run, and allowing for people to cheat by altering their frame-rate and faking lag.

You say you understand the concept of using Time.deltaTime, why don't you want to rely on it? I see you're new to 3D development, but I assure you this has absolutely now downside, only upsides.

If you however insist on doing everything in a fixed timestep, don't use Update() but use FixedUpdate(). You can set the fixed time step for this function under Edit > Project Settings > Time > Fixed TimeStep. This means all physics calculations will also be run more or less frequently, so be careful with this. It's also designed to 'catch' missed iterations, which it will que up and run if there was a moment's lag due to a garbage collector spike for instance.

As for using inches for your in-game units, that's completely up to you. The units Unity uses are only relative to eachother, so you can define them as you want to. The only place you have to tweak something is the gravity, as it's by default set to -9.81, which implies meters/second. If you change that, or keep it in mind when using physics, you can just as well use inches/second_on_mars.

Good luck with your project and welcome to Unity ;)

Comment
Add comment · 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
0

Answer by Waz · Jul 30, 2011 at 04:59 AM

You cannot set the display framerate, simply because you cannot force a computer to go faster.

You can set the physics frame rate in ProjectSetting -> Physics.

Comment
Add comment · Show 4 · 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 Joshua · Jul 30, 2011 at 05:05 AM 0
Share

Sorry for being rude, but that's simply wrong. You can set a target framerate, that only won't be met if the computers specs are either to low (which you can catch by adjusting quality, etc) or there's a sudden lag.

avatar image Waz · Jul 30, 2011 at 05:56 AM 0
Share

You've listed exactly why it can only ever be a "target" framerate, I never said "target", and in your own answer you also repeat that it is inaccurate.

This is why we use Time.deltaTime. If we don't, then every frame miss causes an ugly jerk in the animation, and users on slow computers that your "quality adjustments" weren't enough for get a completely different, slow-motion experience. Not to mention users with faster computers complaining.

avatar image Joshua · Jul 30, 2011 at 06:04 AM 0
Share

But computers that are too slow will get this "completely different, slow-motion experience" anyway, as the entire physics system is based on a fixed timestep.

avatar image Waz · Jul 30, 2011 at 06:18 AM 0
Share

Unity will keep running fixed frames and starving the display framerate if it has to - a good reason to not do too much in FixedUpdate. By comparison:

 transform.position += velocity * Time.deltaTime;

takes the same amount of time to execute regardless of framerate, and that's why we do it. Physics is too expensive to do with continuous functions and far cheaper to do discretely, hence the need for FixedUpdate.

When someone asks here "How do I do X", we have a duty not just to tell them the literal answer, but to give the reasons not to do X too. Your answer does that just fine.

avatar image
0

Answer by Waz · Jul 30, 2011 at 05:02 AM

If you use something other than meters, you will need to change Gravity accordingly. A few things don't work quite right with non-meter dimensions. One is the TreeCreator, which assumes meters given the limited unit ranges it allows.

Comment
Add comment · 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
0

Answer by SirMacJefferson · Jul 30, 2011 at 05:40 AM

Thanks for the answers,

Regarding some of the things said:

The first result in a search for 'Unity3d fixed framerate' already answers your question perfectly, I realize you're new to this site but in the future please use the search function.

I searched Google for it a few times with various wording, but I kept getting things like "How to show the user's framerate" rather than fixing the framerate specifically. The manual/reference didn't seem to offer help either (not saying they're bad documents because of that).

You say you understand the concept of using Time.deltaTime, why don't you want to rely on it? I see you're new to 3D development, but I assure you this has absolutely now downside, only upsides

The explanation (which isn't very justified) was that in my GDD, some things (such as jumping) would move X units/frame for 18 frames..I guess I'll just translate them into seconds instead of frames.

EDIT-Sorry, forgot something:

Something I don't understand, however, is what a 'meter' is, specifically. Sorry, I've gotten used to moving things by pixels in 2D games (X + 10 would be 10 pixels to the right), but Unity seems to do things differently. I don't really understand how the gravity would relate to this..? Is the gravity the amount of pixels each meter takes you?

Thanks again for the help!

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How does Time.deltaTime provide smoother physics functions? (Frame rate question) 2 Answers

Can I make physics engine speed dependent on frame rate? 2 Answers

Lower Frame rate for less polys ? 1 Answer

Experiencing strange problems with Mathf.SmoothDamp function 2 Answers

Retina specific framerate drop on specific function 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