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 POLYGAMe · Dec 27, 2011 at 09:40 PM · speed issues

Game behaves differently in build version

Hi there,

I have a little racing game that is coming along nicely but for some reason has just started playing up.

My car behaves perfectly in the preview window but when I build the game, acceleration and braking are ridiculously strong, yet the top speed is the same...

I am using Time.deltaTime... so I can't see why this would be happening... here is the code:

 // If W key is pressed, accelerate
     
         if (Input.GetKey("w"))
     
         {
     
             if (fSpeed < fMaxSpeed)
     
             {
     
                 fSpeed += fAcceleration;
     
             }
     
         
     
             transform.Translate(0.0f, 0.0f, fSpeed * Time.deltaTime);
     
         }
     
         // If S key is pressed, brake
     
         else if (Input.GetKey("s"))
     
         {    
     
             if (fSpeed > 0.0f) // Brakes only work if car is moving
     
                 {
     
                     fSpeed -= fBrakeForce;
     
                     transform.Translate(0.0f, 0.0f, fSpeed * Time.deltaTime);
     
                 }
     
         }
     
         // If no input, slow down gradually
     
         else
     
         {
     
             if (fSpeed > 0.0f) // So that car doesn't move in reverse when comes to stop
     
             {
     
                 fSpeed -= fDecceleration;
     
                 transform.Translate(0.0f, 0.0f, fSpeed * Time.deltaTime);
     
             }
     
         }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by coolthemanp6p · Dec 27, 2011 at 10:48 PM

Time.deltaTime is basicly FPS or Frames Per Second. The editor uses less fps, which when you build your FPS is higher. So it's fSpeed * Time.deltaTime. Imagine this your speed is 10 and first the editor's FPS is 20. 10 x 20 = 200. Now you build. 10 x 30 = 300. Just by the fps being 10 more your speed increases by 100. I would suggest bringing the speed down.

Comment
Add comment · Show 5 · 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 FLASHDENMARK · Dec 27, 2011 at 10:40 PM 0
Share

Time.deltaTime is not frame rate driven, but time driven.

avatar image POLYGAMe · Dec 27, 2011 at 11:20 PM 0
Share

Yeah and the speed is not the problem... it's the acceleration and braking... happens way too fast...

avatar image POLYGAMe · Dec 27, 2011 at 11:27 PM 0
Share

Oh, also... acceleration , deceleration and braking figures are already very low (0.2, 0.1 and 0.5). f$$anonymous$$axSpeed is set to 25.

Any help greatly appreciated!

avatar image Bunny83 · Dec 28, 2011 at 12:18 AM 3
Share

Acceleration and deceleration follow a quadratic curve and can't be scaled linearly with the frame rate.

Time.deltaTime is NOT the FPS, it's the time passed between two frames (the delta). It can be calculated with 1/FPS.

If you multiply a value you use in a linear calculation with Time.deltaTime it becomes frame-independent. Now the value specifies the ammount per sec.

Example: value == 5

 value*Time.deltaTime  at 1 FPS(deltaTime == 1/1 == 1)
 == 5
 
 value*Time.deltaTime  at 10 FPS(deltaTime == 1/10 == 0.1)
 == 0.5

At a higher FPS the value per frame will be lower to get the same value after 1sec. The second example has a frame rate of 10 so it's executed 10 times in one sec. 0.5 * 10 == 5.

Accelerated movement won't work since a quadratic function can't be scaled linearly. You should use $$anonymous$$onoBehaviour.FixedUpdate for such calculations since the calling-rate will be fixed (corrected) to match the desired physics-frame-rate.

The explanation of @coolthemanp6p is wrong. Usually for all linear movement / change just use Update with Time.deltaTime. For all physics or physics-like calculations use FixedUpdate with Time.deltaTime. Don't forget the deltaTime in FixedUpdate to have all your values time-based ins$$anonymous$$d of (physics-)frame based.

Don't change your physics - framerate or it will have an impact on the calculations again.

avatar image POLYGAMe · Dec 28, 2011 at 12:47 AM 0
Share

Thanks a lot for that!!!

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

7 People are following this question.

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

Related Questions

Does transitioning between scenes speed up in final build 1 Answer

animation.speed does not work when disabling/enabling renderer 1 Answer

The build version of my android game doesn't work (in unity remote it works perfectly) 0 Answers

Update() intervals and fps 0 Answers

Why does scripting backend slow down android app? 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