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
0
Question by Abdo023 · Apr 30, 2021 at 12:06 PM · coroutinelerpsmoothingeasing

How to use easing inside coroutine to change a float value?

I would like to increase the value of a float over time but with added In-Out easing. Here I'm using Mathf.Lerp and I know there is Mathf.Smoothstep but in SmoothStep, I can't seem to control the speed of the easing itself. I would like the easing to start from a certain value to another value over a specific time(range?) I choose. For example, if the float is changing from 0 to 100, I would like the easing to be from 0 to 20 and again from 70 to 100.

Here is the current code I'm using:

 float minValue = 0;
 float maxValue = 100;
 float duration = 10;
 
 float value;
 
 void Start()
     {
           StartCoroutine(IncreaseSpeed(minValue, maxValue, duration));
     }

  private IEnumerator IncreaseSpeed(float start, float end, float duration)
     {
         float time = 0;
         while (time <= duration)
         {
             time = time + Time.deltaTime;
             value = Mathf.Lerp(start, end, time / duration);

             yield return null;
         }
     }



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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by andzq · Apr 30, 2021 at 12:30 PM

hi (: try this:

     float minValue = 1;
     float maxValue = 2;
     float duration = 3;
     float value;
     void Start()
     {
         StartCoroutine(IncreaseSpeed(minValue, maxValue, duration));
     }
     private IEnumerator IncreaseSpeed(float start, float end, float duration)
     {
         float percent = 0;
         float timeFactor = 1 / duration;
         while (percent < 1)
         {
             percent += Time.deltaTime * timeFactor;
             value = Mathf.Lerp(start, end, Mathf.SmoothStep(0,1,percent));
             yield return null;
         }
     }
Comment
Add comment · Show 1 · 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 Abdo023 · Apr 30, 2021 at 06:42 PM 0
Share

Thank you for your help. This does have an "Easing" effect. But how do I control it? how do I make it slower or faster?

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

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

If statement not being fullfilled until GameObject inspected in inspector. 0 Answers

LERP gives final value way too early 2 Answers

Howcome this coroutine loops once? 2 Answers

Lerp coroutine not executing 0 Answers

Slow Mo effect with Time.timeScale? Dont understand Lerp and Corutines... 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