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
1
Question by Daniel G · Jul 08, 2013 at 07:02 PM · javascriptlerpslerp

How to Lerp or Slerp Time.timeScale change

Hello, I want to have a smooth transition between,

time.timeScale == 1.0 and time.timeScale == 0.8

How would I go about doing this in JavaScript?

Thanks Daniel

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 b1naryatr0phy · Mar 29, 2017 at 10:20 AM 0
Share

Create a modified deltaTime implementation that is independent of the time scale.

https://forum.unity3d.com/threads/time-realdeltatime.3866/

1 Reply

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

Answer by robertbu · Jul 08, 2013 at 08:08 PM

This is a tricky problem. The issue is that typically 'Time.deltaTime' is use in some form as part of a Lerp(). But here 'deltaTime' will be changing as you change Time.timeScale. One imperfect solution is to grab an arbitrary deltaTime and use that. Sample code:

 #pragma strict
 
 private var myDeltaTime : float;
 private var speedup = false;
 var maxTimeScale = 8.0;
 var speed = 4.0;
  
 function Start() {
     myDeltaTime = Time.deltaTime; 
     Debug.Log(myDeltaTime); 
 }
  
 function Update() {
     if (Input.GetKeyDown(KeyCode.A))
         speedup = true;
     
      if (speedup) 
          Time.timeScale = Mathf.MoveTowards(Time.timeScale, maxTimeScale, myDeltaTime * speed); 
 }

This code speeds up Time.timeScale when the 'A' key is pressed.

Comment
Add comment · Show 7 · 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 Daniel G · Jul 09, 2013 at 03:29 PM 0
Share

hmm.. Seems like there has to be a simpler way? A different function thats more like simple math? Like this: $$anonymous$$athf.Lerp (from : float, to : float, time : float) : float

so

$$anonymous$$athf.Lerp ((Time.timScale == 1.0), (Time.timeScale == 0.8), 2);

@robertbu

avatar image robertbu · Jul 10, 2013 at 01:26 AM 0
Share

I know a fair bit about Unity, and I don't know if a simpler way. If you were working with something besides Time.timeScale, you could do it in one line:

 new_val = $$anonymous$$athf.$$anonymous$$oveTowards(cur_val, dest_val, Time.deltaTime * speed);

or

 new_val = $$anonymous$$athf.Lerp(cur_val, dest_val, Time.deltaTime * speed);

But since you are changing timeScale, Time.deltaTime is effected impacting the Lerp()/$$anonymous$$oveTowards(). Since you are working with timeScale, you have to jump through some hoops to get it to work.

avatar image Loius · Jul 10, 2013 at 01:32 AM 2
Share

use Time.realTimeSinceStartup, which is not affected by timeScale.

 (myDelta = Time.realTimeSinceStartup - lastTimeIRan);
 // use myDelta
 lastTimeIRan = Time.realTimeSinceStartup ;
avatar image robertbu · Jul 10, 2013 at 03:03 AM 0
Share

@Louis - nice.

@$$anonymous$$ G - so the code becomes (untested):

 private var lastTime : float;
 private var speedup = false;
 var maxTimeScale = 8.0;
 var speed = 4.0;
  
 function Start() {
     LastTime = Time.realTimeSinceStartup;
 }
  
 function Update() {
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A))
        speedup = true;
  
     if (speedup) {
       var myDeltaTime = Time.realTimeSinceStartup - lastTime;
       lastTime = Time.realTimeSinceStartup;
       Time.timeScale = $$anonymous$$athf.$$anonymous$$oveTowards(Time.timeScale, maxTimeScale, myDeltaTime * speed); 
     }
 }

Not less complicated, but more accurate.

avatar image Daniel G · Jul 11, 2013 at 03:50 AM 0
Share

@robertbu Yes that seems better, I will test it out i got a massive script made haha ill see on implementing :D! Thanks for the help and ill get back to ya'll tomorrow when i get a chance to try :D

Show more comments

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

16 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

Related Questions

Multiple Cars not working 1 Answer

Smooth the Changes in TimeScale, in TimeBending script 0 Answers

How to lerp an object's scale? 2 Answers

Slerp, lerp or something else? 3 Answers

How to use Lerp? 3 Answers


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