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
-2
Question by GamezAtWork · Jan 09, 2011 at 05:41 AM · timing

Timings completely different on different computers

Can someone help me with this? I have a feeling its a simple idea, but... I just can't get it...

The thing is, I'm using two computers. And on both of them, there are quite a few differences based on Update...

Enemies move faster on the faster computer, attacks trigger earlier on the faster computer, etc etc...

I think it has to do with relying on FrameRate, but I'm not too sure about how to change my FrameRate-dependant code to a more reliable, global code...

Thanks!

Comment
Add comment · Show 4
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 Jessy · Jan 09, 2011 at 06:02 AM 0
Share
  • because it's the second page of the scripting manual. http://unity3d.com/support/documentation/ScriptReference/index.html

avatar image yoyo · Jan 09, 2011 at 06:07 AM 0
Share

That's the first page ;) ... you want http://unity3d.com/support/documentation/ScriptReference/index.$$anonymous$$eeping_Track_of_Time.html

avatar image Jessy · Jan 09, 2011 at 06:14 AM 0
Share

The page that you linked is what I'd call the second page, and what I was referring to. You can't tell what page it is if you don't see the pages listed. (I'd call my link the table of contents.) You're probably right that this person needed the direct link, though, however, I have my doubts that they'll read it, or Eric's answer. Seems a lot of typing when the info is easy to get to; I don't understand this at all... 8-/

avatar image yoyo · Jan 09, 2011 at 06:16 AM 0
Share

True, but that second page is awfully sketchy on details -- it says what to do, but very light on explaining why.

2 Replies

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

Answer by yoyo · Jan 09, 2011 at 06:14 AM

As Eric5h5 says, you can use Time.deltaTime. So if (for example) you are moving something a distance of x per frame, instead move it x * Time.deltaTime -- now you are moving distance x per second, instead of x per frame (yes, you'll want to make x bigger). Since seconds are constant (barring serious gravitational disturbances or relativistic effects) and frames are not, you will now get constant velocity.

The other option is to make your updates in FixedUpdate instead of Update -- FixedUpdate is called a fixed (surprise!) number of times per second, so if you move distance x, you'll be moving k * x per second, where k is the fixed update rate (typically 60, but can be configured).

Note that if your frame rate is low, then FixedUpdate is inefficient -- you're moving an object more often than you're displaying it, which is pointless. Better to move once per display refresh (i.e. in Update) instead, and use deltaTime appropriately.

The exception is for operations like integration of physics calculations which are sensitive to the timesteps involved. Like Jessy says, read the manual ... ;)

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 Eric5h5 · Jan 09, 2011 at 07:42 AM 0
Share

FixedUpdate isn't necessarily fixed, either...depends on the framerate and what you have maximum allowed timestep set to. Plus you can get jittery-looking movement since FixedUpdate doesn't usually match the framerate. Basically you really shouldn't use FixedUpdate as a substitute for proper framerate-independence; just use Update or coroutines and Time.deltaTime.

avatar image GamezAtWork · Jan 09, 2011 at 11:19 AM 0
Share

Thanks for the help! Your answer was very helpful. And damn, didn't notice the Time section, argh...

avatar image
3

Answer by Eric5h5 · Jan 09, 2011 at 05:56 AM

Use Time.deltaTime where appropriate. If you just have things happen every frame without regarding the time difference from the last frame, then naturally the timings will differ as the framerate varies.

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

No one has followed this question yet.

Related Questions

Update() calls start several seconds after launch 0 Answers

Making Enemy Retreat 1 Answer

Getting two barrels to fire alternately 1 Answer

What options do I have for firing 'events' at a specific time? (Co-routines, polling, any others?) 1 Answer

Determine exact timing of screen refresh / flip 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