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 ragnaros100 · Jul 08, 2013 at 06:46 PM · c#issuemathfmathf.lerp

Mathf.Lerp supposed to be in Update()?

I am experimenting with some mathf.Lerp... (nothing I haven't done before) but I can't figure out why my numbers keep resetting every frame? Isn't Matf.Lerp supposed to interpolate from a to b? anyways.. Here's my code simplified:

 void Update()
 {
    if(someBool == true)
    {
       someFloat = Mathf.Lerp(0, 10, Time.deltaTime * 3);
    }
 }
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

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

Answer by Kiloblargh · Jul 08, 2013 at 06:55 PM

Time.deltaTime is the time in seconds elapsed between this frame and last frame.

Time.deltaTime * 3 is the time it takes to render 3 frames. It will probably be around .05 but will never reach 1 unless your game is seriously lagging.

Lerp will give you a value between the first value and the second value based on where the third value is between 0 and 1.

So it will output something like 0.5 every time, varying based on your FPS. You're not incrementing anything so it will not increase.

I don't get why Lerp is so hard for people to understand.

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 ragnaros100 · Jul 08, 2013 at 06:58 PM 0
Share

but what if I wanted to have my variable Lerp from 0 to 10 in 5 seconds? what should I write? something like Time.time / 5???

avatar image Kiloblargh · Jul 08, 2013 at 07:03 PM 0
Share
 var startTime : float;
 var elapsedTime : float;

 startTime = Time.time; //call once to begin the transition
 
 elapsedTime = Time.time-startTime; // do this part in Update
 if (elapsedTime <=5)
      {
      someFloat = $$anonymous$$athf.Lerp (0, 10, elapsedTime/5);
      }


avatar image ragnaros100 · Jul 08, 2013 at 07:05 PM 0
Share

Thanks :)!

avatar image Kiloblargh · Jul 08, 2013 at 07:10 PM 0
Share

Can you see why that works? $$anonymous$$athf.Lerp is actually unnecessary in this case. You could just say,

 someFloat = elapsedTime *2;


and get the same result.

avatar image
0

Answer by TonyLi · Jul 08, 2013 at 06:51 PM

The third parameter should always be in the range [0..1]. Rewrite your method to normalize the value properly.

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

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

Multiple Cars not working 1 Answer

Mathf.Lerp not working, why? 1 Answer

Distribute terrain in zones 3 Answers

how to use time on lerp 2 Answers

Using Blend Trees, I want to switch smoothly based on input, but my input is simulated. How can I achieve this? 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