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
1
Question by Miguel_cs · Jul 31, 2017 at 11:00 PM · updatescorefixedupdate

score, Update, Fixed Update and screen refresh rate (fps)

Hello, I made my first game and I noticed I made a mistake, when counting the score I was incrementing 1 point for every update call, then I remembered Update depends on frame rate of the device, so it's kinda not constant. So I thought: solution 1: add 1 point every FixedUpdate so that it is constant, ( but this seems not good practice since it's said to use only rigidbody stuff on fixedupdate)

solution 2: count the time interval in each update call and add points , but I don't know exactly how to keep it around 1point per 0.02 sec , maybe do some kind of proportion?

Also, In a simple game that needs instant screen reaction to touch, should I increment fixed update to something lke 60calls/s and limit frame rate of screen to 60 also? or what value should I give to each one? To lessen small delays on touch/screen reaction

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
Best Answer

Answer by nt314p · Jul 31, 2017 at 11:21 PM

You should use Time.deltaTime.

https://docs.unity3d.com/ScriptReference/Time-deltaTime.html

Example code:

 void Update () {
     score += 60f * Time.deltaTime;
 }

Please don't hesitate to ask any questions!

Remember, Time.deltaTime is a really small number (more specifically, it is "The time in seconds it took to complete the last frame.") For example, it might be 1/60 for 60 FPS.

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 Miguel_cs · Jul 31, 2017 at 11:32 PM 0
Share

Probably is the best solution, giving around 1 point per update as well! Do you know the average fps on a mobile or how can i check the fps I have while playing my game in the mobile phone? Also, do you have any opinion on the second question? about changing fixedupdate time from 0.02? @n314p

avatar image nt314p · Jul 31, 2017 at 11:56 PM 0
Share

If you are using physics, changing your fixed update time will make the game feel smoother and responsive but try not to push it because it might start to lag.

As for the checking fps on a mobile device, ask another question and give me the link (its not good to answer a question within a question).

Also, if my answer is satisfactory, you know what to do.

avatar image
0

Answer by Sergio7888 · Jul 31, 2017 at 11:22 PM

You can use a float to hold the nextTime and compare in the update function.

float nextTime;
float waitTime= .02f;
int score=0;
void Update(){
    if(Time.time > nextTime ){
        nextTime = Time.time + waitTime;
        score++;
    }
}
Comment
Add comment · Show 1 · 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 Miguel_cs · Jul 31, 2017 at 11:27 PM 0
Share

Hum the idea is not bad but I think that, for example, if update is called when Time.time is still more 0.005 than nextTime, you have to wait until next frame. Or being, if update is called before the 0.02 wait

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

69 People are following this question.

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

Related Questions

Interpolation with jumping - Acting Weird. 1 Answer

FixedUpdate limits: consistant 0.01 s on mobile devices? 1 Answer

iOS Lag From Updating Score 0 Answers

FixedUpdate performance doubts 2 Answers

Placing Input.GetkeyDown() inside FixedUpdate() slows down the rate I can fire at 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