• 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
Question by Igor_Vasiak · Oct 18, 2017 at 02:29 PM · scripting problemtimetimescaleslowmotionspeed issues

Calcule Player's Speed based on Time.timeScale

Hey! I am trying to give my players some cool abilities, and getting some inspiration from DBS (DBS fans will understand) and Kameo - EoP I've decided to make super speed. There's only a problem with it.

The Problem

I'd like to use Time.timeScale to make some good slow-mo, to give the sensation of ultra high speed. But the problem is: it slows the player down as well.

Obviously, you might be thinking. Yes, I knew it would happen, so I've started looking for solutions. Keep in mind that what I want is to have the player at a scaled speed (just like if it wasn't affected by timeScale). I've tried the following ones:

 speed * (Time.deltaTime + (1 + (1 - Time.timeScale)));
 speed * Time.fixedUnscaledDeltaTime;
 speed * Time.unscaledDeltaTime;

None of those work. I can't simply set the speed when the player is on slow mo, because the player will make the slow mo more intense within time, raising its speed (making the game slower).

So, I need a system that keeps the player at normal speed even if Time.timeScale is at 0.0001. Quite crazy, right? Another thing to keep in mind is this line:

 Time.fixedDeltaTime = 0.02f * Time.timeScale;

I am making the Fixed Time Step scale within timeScale, so I can be sure that I have fluid moves. Help? Thanks in advance.

Comment

People who like this

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

Answer by unit_nick · Oct 18, 2017 at 03:13 PM

Just to clarify. You use Time.fixedDeltaTime inside of FixedUpdate, it represents the time past since FixedUpdate was last called. You use Time.deltaTime inside of Update, it represents the time past since Update was last called.

To accelerate you speed you have to increase the value. Because Time.timeScale is less than 1 when slowed you must divide speed rather than multipy it. So..

 speed /= Time.timeScale;

should work

Comment
Igor_Vasiak
Bunny83
MacDx

People who like this

3 Show 15 · 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 Igor_Vasiak · Oct 18, 2017 at 03:46 PM 0
Share

It kinda of works. But just to let you know, whenever I set the game with a speed like, 0.05, it doesn't works. And that's because I'm still multiplying it by fixedDeltaTime (I use physics) to be sure that the movements don't happen depending of the framerate.

Also, Time.deltaTime is automatically converted to Time.fixedDeltaTime inside FixedUpdate, so it doesn't matter which one I use. It'll always give me the same result.

What happens is, when I multiply the player's speed by the fixed fixedDeltaTime (0.2 * Time.timeScale) I'm always decreasing the hell out of the player, and I needed a solution for this as well.

So what I did? I did this:

 speed * (Time.deltaTime + (1 + (1 - Time.timeScale)));

Which is basically

 speed * (1 - Time.timeScale + 1 + Time.deltaTime) =
 speed * (1 - 0.5 + 1 + Time.deltaTime) =
 speed * (1.5 + Time.deltaTime)

Do you get it? I'm not multiplying anything by below one numbers. I'm multiplying by numbers above one, increasing player's speed (and after that probably decreasing it with an always smaller fixedDeltaTime).

Thanks for taking your time to help me, but yours solution didn't work. :)

avatar image unit_nick Igor_Vasiak · Oct 18, 2017 at 03:52 PM 0
Share

Also, Time.deltaTime is automatically converted to Time.fixedDeltaTime inside FixedUpdate, so it doesn't matter which one I use. It'll always give me the same result.

ummm.... really? where do you get this information?

and why go through all you complicated plus and minus stuff when the correct solution is to divide by the time scale?

to add.... your solution of adding 0.5 will only work when timeScale is 0.5. and then you go and add Time.deltaTime which is a totally random value based on framerate. therefor they do not relate to each other in any way and will almost always produce inconsistent speeds, as i believe you are experiencing.

avatar image Igor_Vasiak unit_nick · Oct 18, 2017 at 04:06 PM 0
Share

ummm.... really? where do you get this information?

I've got this information on Unity's Scripting Manual.

and why go through all you complicated plus and minus stuff when the correct solution is to divide by the time scale?

To not use Time.fixedDeltaTime or Time.timeScale as crude factors, because it doesn't work. There I set the negative of Time.timeScale + 1 + Time.deltaTime (or fixed, if you want). Logically this should work, but it doesn't.

your solution of adding 0.5 will only work when timeScale is 0.5.

Not really. It was an example. It works if the timeScale is above or equals to 0.1.

you go and add Time.deltaTime which is a totally random value based on framerate

As I said, it's not random. It's converted. Equals to fixedDeltaTime.

will almost always produce inconsistent speeds, as i believe you are experiencing

Nope. That's not happening. What is happening is that the speed gets reduced as timeScale gets reduced; therefor it is being affected by timeScale.

Any other ideas?

Show more comments
avatar image MacDx Igor_Vasiak · Oct 18, 2017 at 03:58 PM 0
Share

Just a suggestion. You could literally speed everything else down, like having a global speed multiplier for everything that is not the player (or maybe a couple of events) and when the time comes, just change that value to manually decrease the speed, instead of using timeScale. The thing with timescale is that it affect physics and when you set it to some "extreme values" physics in your game will get funky, this isn't a problem if you aren't using the physics system extensively in your game but if you do, you are kind of shooting yourself in the foot.

avatar image Igor_Vasiak MacDx · Oct 18, 2017 at 04:01 PM 0
Share

I have tried already that, it doesn't give the same effects that I want.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

126 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 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

how to get smooth slow motion? 4 Answers

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

Pause menu... Isn't pausing everything... 1 Answer

AudioSources don't play when setting Time.timescale = 0 1 Answer

Pausing an Invoke for a time 2 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