Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 murkertrer · May 10, 2016 at 03:59 AM · coroutinelerptime.timescale

Slow Mo effect with Time.timeScale? Dont understand Lerp and Corutines...

I allready have a working code to achieve a slow mo effect... It falls down and then up- but, I think it can be made way cooler by someone who understands coroutines and lerp properly (this person is not me);

How could I implement an effect similar to this one by using Lerp or Slerp? thank you for the help :)

 public class TimeManipulation : MonoBehaviour {
 
     KeyCode timeManipualtionKey;
     public bool manipulatingTime;
     public bool manipulatingDown;
     public bool manipulatingUp;
     public float manipulationRate;
     public float timeManipulationDown = .5f;
     public float lerpSpeed = 10;
     public float durationOfManipulation = 2;
 
     float it = 1;
     float increment = .05f;
 
     void OnEnable()
     {
         timeManipualtionKey = this.GetComponent<Attributes> ().timeManipulation;
     }
 
     // Update is called once per frame
     void FixedUpdate () {
 
         if (Input.GetKeyDown (timeManipualtionKey)) {
             manipulatingTime = true;
             manipulatingDown = true;
         }
 
         if (manipulatingTime) {
             if (manipulatingDown) {
                 if (it >= .5f) {
                     print ("manipulating Down");
                     it -= increment;
                     Time.timeScale = it;
                     Time.fixedDeltaTime = 0.02f* Time.timeScale;
                 } else {
                     print ("finished manipulation Down");
                     manipulatingDown = false;
                     StartCoroutine (TimeInTheZone ());
                 }
             }
 
             if (manipulatingUp) {
 
                 if (it <= 1) {
                     print ("starting manipulating up");
                     it += increment;
                     Time.timeScale = it;
                     Time.fixedDeltaTime = 0.02f * Time.timeScale;
 
                 } else {
                     print ("manipulation ended");
                     manipulatingUp = false;
                     manipulatingTime = false;
                 }
             }
         }
     }
 
     IEnumerator TimeInTheZone()
     {
         print ("starting wait");
         yield return new WaitForSeconds (1);
         print ("wait ended");
         manipulatingUp = true;
         yield return null;
 
     }
 }
Comment
Add comment · Show 2
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 Highwalker · May 10, 2016 at 06:05 AM 0
Share

I don't think lerp or slerp would really be applicable here. If that code works I would just stick with it.

But I would stay away from using fixedDeltaTime. That just sets the intervals at which physics update. But if you're scaling down the timeScale, there's no need to mess with the way physics update, since it's reliant on timeScale to begin with. I would also put it in a regular Update function rather than a FixedUpdate. Since FixedUpdate updates with the physics, and is really only used to make things play nice with physics.

avatar image murkertrer Highwalker · May 11, 2016 at 05:34 PM 0
Share

Thank you for the input <3

1 Reply

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

Answer by JoshDangIt · May 10, 2016 at 05:21 PM

Unity's scripting reference does an awful job of explaining Lerping. Here's a guide I found that does a better job of explaining it.

http://www.blueraja.com/blog/404/how-to-use-unity-3ds-linear-interpolation-vector3-lerp-correctly

Even though it's a guide on Vector3.Lerp, Mathf.Lerp is basically the same concept.

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

44 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

Related Questions

object's children not moving with it when using a Lerp-ing coroutine 0 Answers

re use a charged ability that isn't at 100 percent? 1 Answer

Why is my Mathf.Lerp not lasting for the intended duration, even though I'm not using Time.time as the t variable? 1 Answer

Lerping alpha with coroutine only lerping first time it is triggered by event 1 Answer

[HELP] How to make camera smooth change position while follow object? 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