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 castor · Jun 17, 2014 at 05:30 AM · timescalecountdowndeltatimetimers

Timescale and Timers - what am I doing wrong?

I have a timer that tells how much time has passed since the start of the game:

 worldTime += Time.deltaTime;

I have a gameObject that moves in the x axis from position A = 0 to B = 5. Everytime it arrives at one of those positions I register how long it took to do so. Here is the code:

 var testCube : Transform;
 private var testCubeAtZero : boolean;
 private var cubeSpeed : float = 1;
 
 var currentTime : float = 0;
 var timeDifference : float = 0;
 
 Update()
 
     if (testCubeAtZero){
         testCube.position.x += Time.deltaTime;
     
         if (testCube.position.x > 5){
             timeDifference = scriptWorld.worldTime - currentTime;
             currentTime = scriptWorld.worldTime;
             
             print("Pos 0 - Time Dif: " + timeDifference.ToString("f2"));
             timeDifference = 0;
             
             testCubeAtZero = false;
         }
     }
     else {
         testCube.position.x -= Time.deltaTime;
     
         if (testCube.position.x < 0){
             timeDifference = scriptWorld.worldTime - currentTime;
             currentTime = scriptWorld.worldTime;
             
             print("Pos 5 - Time Dif: " + timeDifference.ToString("f2"));
             timeDifference = 0;
             
             testCubeAtZero = true;
         }    
     }


When the timeScale is 1, it takes 5.04 seconds to go from A to B and vice versa. If I increase the timeScale it starts to take longer from A to B and the values are no longer stable (e.g. with timeScale = 30 it takes around 6 seconds and the higher I go in the timeScale the worst it gets )

I need the time it takes between the two points, in "game time" to be always the same (5.04 secs) no matter how fast or slow the timescale is. Am I doing something wrong? I can't figure it out.

Any help very appreciated!

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 rutter · Jun 17, 2014 at 05:51 AM

Let's suppose your game is running at a nice and smooth 60fps. That means each frame takes about 17ms to process and render, so Time.deltaTime will be about 0.017.

If you set Time.timeScale to 30, you'll tell Unity to pretend that 510ms have passed between frames. At that point, Time.deltaTime will indicate that your update calls are coming in roughly half-second intervals. At that speed, it's no wonder you're starting to lose accuracy.

You'll be hard pressed to find a game engine that can reliably simulate a 30x speed increase.

Perhaps there are other ways to accomplish the effect you're looking for?

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 castor · Jun 17, 2014 at 05:45 PM 0
Share

Thanks for the reply. In my project I need to allow the player to fast forward time (similar to The Sims x3 time speed) so he doesn't have to wait for certain events to happen. The problem is that I need something around 7 $$anonymous$$utes to take 4 to 5 seconds (timeScale = 90). How else would I be able to achieve something like this?

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

22 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

Related Questions

Game over scene when the time is up ? 2 Answers

Pause game that not using deltatime for movment 1 Answer

Time.unscaledDeltaTime problem on android when app minimized and maximized? 1 Answer

Ignore timeScale when using Time.deltaTime 2 Answers

Accurate timing while using timeScale. 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