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 designico · Nov 15, 2013 at 07:22 PM · lerpsmooth

How to smooth a single value over time?

Hey guys,

I need to smooth a single variable that changes its value overtime. I know that the lerp function should go for this, but therefor you need to have a start value and a target value, I only have one.

Got someone have an idea? Thanks!

Comment
Add comment · Show 8
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 Starwalker · Nov 15, 2013 at 07:28 PM 0
Share

newValue += newValue * Time.deltaTime, put this in the Update code.

If you want the effect of newValue be reflected on something in past, put Valeu = newValue, in LateUpdate()

avatar image fafase · Nov 15, 2013 at 07:32 PM 0
Share

What is a smoothed value according to you?

avatar image tanoshimi · Nov 15, 2013 at 07:56 PM 0
Share

How can you "smooth" the change in a variable, unless you know what it's changing to?

avatar image Starwalker · Nov 15, 2013 at 08:02 PM 0
Share

He wants to smooth input, hence to do that you have the split the input between 2 update loops, in order to predict. All input will be handled in LateUpdate, and the new value will be lerped in Update.Because LateUpdate happens after Update.

avatar image tanoshimi · Nov 15, 2013 at 08:11 PM 1
Share

@Starwalker - but that's not what the code in your first comment does... all that does is exponentially increase the value of newValue!

Show more comments

1 Reply

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

Answer by designico · Nov 15, 2013 at 09:22 PM

Now I tried this one:

 void Update ()
     {        
 velocityX1 = velocityX;
         
     } 
 
     void LateUpdate ()
     {
         velocityX2 = velocityX;
         
         finalVelocityX = Mathf.Lerp(velocityX1, velocityX2, (0.0002f* Time.time));
         
         
         /// Rotate by using arms
         playerTurning.Rotate(0.0f,(finalVelocityX* -(rotateForceInput) * Time.deltaTime),0.0f );
     }

No error, but it has no effect as well :-(

Comment
Add comment · Show 4 · 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 Starwalker · Nov 15, 2013 at 11:01 PM 1
Share
 void Update ()
     {   
 
 // x2 is old rotation times new input.
 
 velocityX2 = velocityX1 * -(rotateForceInput) * Time.deltaTime; // New velocity, New $$anonymous$$AX
  
     } 
  
     void LateUpdate ()
     {
        
  // Lerps new value of X2, with old value of X1, over 0.002 f secs
        finalVelocityX = $$anonymous$$athf.Lerp(velocityX1, velocityX2, (0.0002f* Time.time));
  
      velocityX1 = finalVelocityX; // Store final velocity for next frame.
  
        /// Rotate by using arms, 
 //set new rotation here.
 
        playerTurning.Rotate(0.0f,finalVelocityX ,0.0f );
     }

Try above code, it might work.

avatar image designico · Nov 16, 2013 at 03:44 PM 0
Share

Thank you I'll check it as soon as possible and than I'll give feedback.

avatar image designico · Nov 18, 2013 at 02:43 PM 0
Share

Thanks man! I had to change the code a little bit but now it works:

 void Update (){        
                 
         // x2 is old rotation times new input.
         velocityX2 = velocityX; // New velocity, New $$anonymous$$AX    
     }
 
     void LateUpdate ()
     {
  
          // Lerps new value of X2, with old value of X1, over 0.002 f secs
         finalVelocityX = $$anonymous$$athf.Lerp(velocityX1, velocityX2, (0.002f* Time.time));
  
          velocityX1 = finalVelocityX; // Store final velocity for next frame.
  
             /// Rotate by using arms
         playerTurning.Rotate(0.0f,(finalVelocityX* -(rotateForceInput) * Time.deltaTime),0.0f );
     }
avatar image Starwalker · Nov 18, 2013 at 06:07 PM 0
Share

Welcome :)

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

19 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

Related Questions

How you change another script value smoothly on trigger 0 Answers

moving between two points over time 1 Answer

How can I smooth out the crouch movement? 1 Answer

Moving an object smoothly with a set distance and time 1 Answer

Smooth Camera/Object Movement 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