Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
3
Question by dissidently · Dec 22, 2010 at 08:54 AM · timeslowtimescalemotionslowmotion

how to get smooth slow motion?

I'm currently using the following script to create slow motion. However it doesn't smooth out the slow motion by adding the frame information for the frames in between the full speed motion and the new slower motion. By this I mean:

full speed has frames A,B,C,D

A true slow motion effect at 50% of real speed would create frames in between the above frames:

A, a, B, b, C, c, D, d

where the lower case frames are exactly halfway between the upper case letters in terms of all object positions and movements.

This is not the case for the below code, instead it does this at 50%

A, A, B, B, C, C, D, D

Where the second A is a repeat of the first A frame, not an effort to figure out the inbetween states of everything.

Is there a way to get true slow motion?

Here's the code I'm using;

var paused : boolean = false;

function Update () { if(Input.GetButtonUp("Jump")){ if(!paused){ Time.timeScale = .5; paused=true; }else{ Time.timeScale = 1; paused=false; } } }

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

4 Replies

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

Answer by Eric5h5 · Dec 22, 2010 at 09:38 AM

Setting Time.timeScale to .5 does result in "true" slow motion; no rendered frames are repeated. The problem you're seeing is that physics runs on its own discrete timer, 50 fps by default, which setting timeScale to .5 effectively halves. One thing you can do is to double the physics framerate to compensate. However, this chews up twice the CPU time when you're not using slow motion. Probably a better solution is to turn on interpolation for rigidbodies, in which case they're interpolated smoothly between each physics frame.

Comment
Add comment · Show 11 · 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 ina · Dec 22, 2010 at 09:46 AM 0
Share

would lerp help at all in this case?

avatar image Eric5h5 · Dec 22, 2010 at 10:03 AM 0
Share

Not directly, but that's a good question, since that re$$anonymous$$ds me of the interpolation setting for rigidbodies, which I managed to completely forget about.

avatar image dissidently · Dec 22, 2010 at 10:40 AM 0
Share

Hey Eric, think you've hit on something here, just about everything in the scene is under the influence of physics forces. Is there a way for me to change the physics discrete timer to ONLY increase during the slowmotion activity?

avatar image dissidently · Dec 22, 2010 at 10:49 AM 0
Share

I've just poked around in the physics settings and cant find where to set the physics framerate...

avatar image dissidently · Dec 22, 2010 at 04:10 PM 1
Share

Eric, you're a LEGEND. thankyou. Interpolation did the trick perfectly, however halved my overall frame rate :(

Show more comments
avatar image
6
Best Answer

Answer by Statement · Dec 22, 2010 at 09:01 AM

Changing Time.timeScale cause Time.deltaTime to scale according to the time scale. For this to have any effect, you must ensure that all your movement/animation made in Update() properly use Time.deltaTime.

Example:

function Update()
{
    transform.Translate(Vector3.forward * Time.deltaTime);
}

Note that you probably should change Time.fixedDeltaTime as the documentation for Time.timeScale suggests in order for your physics and other fixed time behaviors to work correctly.

You'd maybe think Unity could derive information somehow between two calls to Update but that is not how it works. It is up to you to scale animation with accordance to Time.deltaTime (which unity does scale for you).

Comment
Add comment · Show 6 · 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 dissidently · Dec 22, 2010 at 03:47 PM 0
Share

I wish that was more straight forward in the documentation.

something like:::::::::: "wanna make slow motion? You need to slow down time, and the speed up the rate things are calculated. You slow down time by changing Time.deltaTime to a number lower than 1. You speed up the rate of calculation of physics and other occurrences during slowdown of time by decreasing the number at Time.fixedDeltaTime." Even this doesn't make logical sense, but will do for now, because it works... increased updates of physics calcs etc would have been better expressed as an INCREASE in rate rather than - time

avatar image dissidently · Dec 22, 2010 at 03:58 PM 0
Share

I added the following to the above script, get a smooth slowmotion, but lose all physics control of my "characters" and frame rate drops by a factor of 10. Time.fixedDeltaTime = (Time.fixedDeltaTime / 5);

avatar image dissidently · Dec 22, 2010 at 03:59 PM 0
Share

oddly enough, there's no mention in the literature of the default rate for Time.fixedDeltaTime, which means I had to do it this way.

avatar image dissidently · Dec 22, 2010 at 04:50 PM 0
Share

Both above answers are right. One is right for physics and one is right for transform created movement... my question is at fault for not expressing which I wanted to remove the stuttering from.

avatar image dissidently · Dec 23, 2010 at 10:00 AM 0
Share

Wrong again, both answers are right, full stop. Just took me to figure out the use properly. Can I give both answers a tick? It seems if I choose one it cancels out the other once...

Show more comments
avatar image
17

Answer by KarlKarl2000 · Jul 01, 2016 at 05:47 PM

A very kind soul on the internet gave the answer on here

http://stackoverflow.com/questions/24344082/how-to-get-smooth-slow-motion-in-unity3d

The gist of it is to add these two lines

   Time.timeScale = 0.5;
   Time.fixedDeltaTime = 0.02F * Time.timeScale;

The fixedDeltaTime is what causes the smoothness to play out. If for whatever reason you need to revert the game back to normal speeds. I apply this after all the calculations are done.

    Time.timeScale = 1;
    Time.fixedDeltaTime = 0.02F ;

Seems to work for me.

Happy coding and hope this helps others.

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 alexjol · Aug 08, 2016 at 11:37 AM 0
Share

This solved it perfectly. Didn't know fixedDeltaTime had a default value of 0.02 ins$$anonymous$$d of 1 as timeScale.

avatar image AltIvan · Jun 04, 2020 at 06:29 AM 0
Share

Be very careful, this solution destroys every physics calculation (e.g. AddForce), it may be better to use "Interpolate" on every rigid body as suggested by Eric5h5.

avatar image
0

Answer by n8burba · Aug 15, 2021 at 09:15 AM

That solution, of multiplying Time.fixedDeltaTime, gives me physics glitches when pausing and unpausing my game.

The solution I came up with is to use Time.timeScale and then mimic FixedUpdate behavior in the Update loop using Time.realtimeSinceStartup:

 float LastFixedUpdateTime = 0f;
 
 void Start()
 {
     LastFixedUpdateTime = Time.realtimeSinceStartup;
 }
 
 void Update(){
     if(Time.realtimeSinceStartup > LastFixedUpdateTime + Time.fixedDeltaTime)
     {
         LastFixedUpdateTime += Time.fixedDeltaTime;
         ProcessFixedUpdate();
     }
 }

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

8 People are following this question.

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

Related Questions

Slow motion problem 1 Answer

Altering Fixed Timestep when your game is running to allow for smooth low Timescale animation. 2 Answers

Calcule Player's Speed based on Time.timeScale 1 Answer

Slow motion all but one - yet another round, hopefully the last 6 Answers

Time.timeScale question 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