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 Karsnen_2 · Jun 25, 2012 at 01:57 PM · iostimescriptingbasicsboolean

How to smooth between values?

Hello,

LOGIC

  • I have an a min and max values. My main task is to smooth the value from the min to max through time.

  • Once it reaches the maximum I swap min and max and start over again.

Can someone suggest me a good solution for this logic.

Thank you...

Comment
Add comment · Show 1
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 AlucardJay · Jun 25, 2012 at 02:03 PM 0
Share

possibly with lerp ?

http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$athf.Lerp.html

2 Replies

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

Answer by Setzer22 · Jun 25, 2012 at 02:04 PM

Unity has this implemented already.

The Mathf.SmoothDamp() method seems to be what you're looking for. It gradually smooths a value over time, that value can only be a float though, so if you want to smooth a vector3, you'll have to do it with all of its 3 components. Check this: http://unity3d.com/support/documentation/ScriptReference/Mathf.SmoothDamp.html

Also I've seen a class called AnimationCurve from the unityEngine, I don't know yet how it works, but seems to be another way to smooth between values using a custom smooth curve.

Also, you may use lerp, but you must take into account that lerp is a linear interpolation (not smoothed). Vector3 can be "lerped" with Vector3.Lerp, no need to do it for all of its 3 components, but as I said, this is not a smoothed translation, just a linear one.

Hope it helped.

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 Karsnen_2 · Jun 26, 2012 at 08:48 PM 0
Share

THAN$$anonymous$$ YOU !!!

avatar image
1

Answer by Tim-Michels · Jun 25, 2012 at 02:06 PM

You should use math functions, depending on the kind of effect you want.

I often use Mathf.Lerp(minVal,maxVal, progress);

The 'progress' parameter is most important here. You have to calculate the progress through a mathematical function, I'll give you an example for a simple smoothed progress.

Just use progress = Mathf.Sin(timeProgress);

Timeprogress is a regular counter, but the 'progress' value will be smoothed. Just use that value inside your Lerp and you should have a good effect. There are also other math functions, but this one is certainly usefull.

Cheers

Comment
Add comment · Show 3 · 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 Kryptos · Jun 25, 2012 at 02:19 PM 0
Share

To add to @tim-michels answer, you can find some "custom" Lerp methods here: http://unifycommunity.com/wiki/index.php?title=$$anonymous$$athfx

avatar image Tim-Michels · Jun 25, 2012 at 02:20 PM 0
Share

Thanks, very usefull :)

avatar image Karsnen_2 · Jun 26, 2012 at 08:48 PM 0
Share

THAN$$anonymous$$S!!!!

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Delaying through yield 2 Answers

Best Practice For Shader Complexity + IOS 1 Answer

Playing an Animation that is within a GameObject 1 Answer

Accesing boolean in a other script? 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