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 /
This question was closed Nov 17, 2015 at 04:22 PM by killer-zog for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by killer-zog · Aug 06, 2013 at 08:50 AM · playertimescalemoveslow

On time slow down only player enable to move

hi, i am using to Time.timeScale for slowing down time by pressing "t". I am getting everything slowed down including the player. Is there anyway to slow down everything except the player. here is my script, i have still some works to do, like adding a coroutine for making the time slow down temporary.

 var slowammount: float = 0.2;
 var visible;
 var skin:GUISkin;
 var slowtex : Texture;
 
 
 function Start()
 { 
  Time.timeScale = 1;
  visible = false;
 }
 
 function OnGUI()
 {
 if (skin != null) 
 {
    GUI.skin = skin;
 }
 if(visible == true){
 if(Time.timeScale == slowammount) {
 
 GUI.DrawTexture(new Rect(0,0,Screen.width, Screen.height), slowtex);
 
 
 
  }
 }
 }
   
     
 function Update () 
 {
 if (Time.timeScale == 1)
  {
   if (visible == false){
 
    if (Input.GetKeyDown("t")) 
     {
 
 visible = true;
 Time.timeScale = slowammount;
  
     }
    }
   }
   
 }
 
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

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by fafase · Aug 06, 2013 at 09:07 AM

Not everything slows down when you set timeScale, only the actions happening in the FixedUpdate or anything using deltaTime or other Time members.

You could get your player going normal speed while everything is slowed down around making its move time independant:

 player.Move(direction*speed);

Then, timeScale won't matter. On the other had, you are not machine independent anymore as you are moving per frame and some computers go faster than others.

You can then use a little trick using Time classes again (I know I said no more time thing but hold on).. You can use store the previous Time.time and subtract the new one.

 float previous;

 float delta = Time.time - previous;
 previous = Time.time;
 player.Move(direction*speed*delta);
Comment
Add comment · Show 10 · 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 killer-zog · Aug 06, 2013 at 09:31 AM 0
Share

can you please tell me how to add this and where? and if there is a tutorial or a documentation!!

avatar image fafase · Aug 06, 2013 at 09:47 AM 0
Share

pretty much the way I did. The previous variable is a global one so right on top of the class, the rest happens in the Update.

avatar image Jamora · Aug 06, 2013 at 09:54 AM 0
Share

Time.deltaTime is the shorthand for that substraction.

avatar image killer-zog · Aug 06, 2013 at 09:55 AM 0
Share

should i create a new script!! i mean in which script i should put this!

avatar image fafase · Aug 06, 2013 at 04:50 PM 0
Share

@Jamora, you are totally right. But the question is about getting timeScale to 0 meaning deltaTime becomes also 0.

You may need to open up the character controller script and find all occurences of deltaTime and replace it with your own delta.

You only need this in the script you want to keep on running full speed when other are low speed.

Show more comments
avatar image
0

Answer by Joyrider · Aug 06, 2013 at 09:02 AM

well, you'd have to manually modify all that is related to the player by multiplying with the inverse of the timeScale, to get everything to normal speed again.

So if timeScale was 0.5f: You'd have to change the player's animation speed to

 animation["Walk"].speed = 1 / Time.timeScale; // The animation will thus play at speed 2, but since the timescale reduces time by half, you get your normal speed again.

and change it back if your timeScale changes

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 killer-zog · Aug 06, 2013 at 09:06 AM 0
Share

thnx, i am using the default fps character comes with unity not the third person controller. There is no walk or running animation in the fps!!

avatar image Joyrider · Aug 06, 2013 at 10:01 AM 0
Share

Well, just replace the "Walk" with whatever animation name you have. This was just an example.

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

collider then change rotation converse? 0 Answers

my player doesn't move at the proper speed for a random time after the level has loaded 1 Answer

space shooter tutorial, cannot move player 1 Answer

Player moving opposite direction when there is a new touch. 2 Answers

How can I convert LOCAL transform.forward to WORLD Vector3? 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