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 Jazzer008 · Feb 20, 2013 at 01:37 PM · lerpmathmathfinterpolationintensity

Mathf.Lerp is just jumping to maximum, no 5.0 interpolation.

 #pragma strict
 
 private var LightState : String = "Off";
 
 function Start(){
     light.intensity = 0.0;
 }
 
 function Update () {
 
     if(GC.hour > 17.5){
         if(LightState == "Off"){
             light.intensity = Mathf.Lerp(0.0,1.0,5.0);    <---------------------
             if(light.intensity == 1.0){
                 LightState = "On";
             }
         }
     }
     if(GC.hour > 5.5 && GC.hour < 15.5){
         if(LightState == "On"){
             light.intensity = Mathf.Lerp(1.0,0.0,5.0);    <---------------------
             if(light.intensity == 0.0){
                 LightState = "Off";
             }
         }
     }
 
 }

What gives? It must be something I don't know about as I can't be much different from the script reference. I thought this was a simple function but it's not performing as expected. ~Confused~

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
1
Best Answer

Answer by Dave-Carlile · Feb 20, 2013 at 01:41 PM

From the documentation.

The t parameter is what you use to control the resulting value. t always varies between 0 and 1. It returns a value that's t percent between the from and to values that you pass in. For example, when t is 0, the function returns the from value. When t is 1, it returns the to value. When t is 0.5 it returns a value halfway between from and to.

You'll note that the documentation states that t is clamped between 0 and 1. So you when you pass in 5, the function converts it to 1, and returns the to value.

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 Jazzer008 · Feb 20, 2013 at 01:45 PM 0
Share

Oh damn, interpreted that incorrectly. I thought it was just simply interpolating between 0 and 1 and that whatever you fed it would be converted into increments. Ie 5/1 = increments of 0.2, 10/1 increments of 0.1

avatar image Jazzer008 · Feb 20, 2013 at 01:46 PM 0
Share

So how would I create a 5 second timer? 1/(Time.deltaTime * 5.0) ?

avatar image Dave-Carlile · Feb 20, 2013 at 01:54 PM 0
Share

You're kind of on the right track, but that formula will always return more or less the same value since Time.deltaTime is generally the same value if you have a constant frame rate. Try something like this (I don't do much with UnityScript/Javascript, so this may not be comletely valid syntax)...

 var timer : float; // declare this at the top
 var totalTime : float = 5.0;

 function Update()
 {
   // add elapsed time to the timer
   timer += Time.deltaTime;

   // what percentage are we to the total time?
   // this will be a value between 0 and 1
   var t : float = timer / totalTime;

   // this will lerp between 0 and 1 over totalTime seconds
   var value : float = $$anonymous$$athf.Lerp(0, 1, t);
   
 }

You might also look at iTween in the asset store. I've not used it, but from what everyone says it handles things like this in a very elegant manner and eli$$anonymous$$ates a lot of ugly code like this.

avatar image Jazzer008 · Feb 20, 2013 at 02:05 PM 0
Share

Yeap that looks good. Thanks for your help. :P

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

10 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

Related Questions

Casting-related error: "^ cannot be applied to double and int" 1 Answer

Mathf.Lerp won't stop snapping 2 Answers

NetworkTransform not interpolating? 0 Answers

AngryBots like character rotation system 1 Answer

Problem with slerp 0 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