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 pdunton · Feb 08, 2014 at 04:17 AM · javascriptlerpnot-working

My Lerp() is not working

Ok, so I have a game where coins are created and fall down, if you click on them they disappear. But, if one reaches the line at the bottom, it's GameOver. So I can correctly test for a coin hitting the line, but after that I want the coin to go to 0,0,0 so it can play a cool animation that I have yet to do. So, I created the script below and the position = Lerp() is not working, the coin just stays where it is. I don't get any errors, it just stays where it is. Hope you can help! Thanks!

 #pragma strict
 var CoinCreater : CoinCreater;
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnTriggerEnter(object : Collider){
     if(object.gameObject.tag == "Coin"){
     
         var CoinFall : CoinFall = object.GetComponent("CoinFall");
         CoinFall.enabled = false;
         
         CoinCreater.scriptEnabled = false;
         CoinCreater.enabled = false;
         
         var extraCoins : GameObject[];
         object.gameObject.tag = "GameoverCoin";
         extraCoins = GameObject.FindGameObjectsWithTag("Coin");
         for(var currentCoin in extraCoins){
             Destroy(currentCoin,0.0);
         }
         var rate : float = 0.05;
         var destination : Vector3 = new Vector3(0, 0, 0);
         var position : Vector3 = object.gameObject.transform.position;
         position = Vector3.Lerp(position, destination, rate * Time.deltaTime);
     }
 }
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 Eric5h5 · Feb 08, 2014 at 04:45 AM

Lerp isn't a function that "magically does stuff over time", it's a very basic math function that just returns a value once, immediately, like all other math functions. The third parameter is a value from 0 to 1, like a percentage, where 0 returns the first parameter, 1 returns the second parameter, and values in between return a percentage between the two. If you want to animate with Lerp you must call it repeatedly every frame while gradually advancing the third parameter from 0 to 1.

Comment
Add comment · Show 2 · 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 Eric5h5 · Feb 08, 2014 at 04:47 AM 0
Share

For example.

avatar image pdunton · Feb 08, 2014 at 05:37 AM 0
Share

Thanks! I did not know that!

avatar image
0

Answer by johnnyjimjams · Feb 08, 2014 at 05:13 AM

This line:

 var position : Vector3 = object.gameObject.transform.position;

creates a copy of the current gameobjects position.... not a reference to it.

So when you change 'position' in the next line, you are only changing your fresh copy of it. 'position' is not attached to your gameObject.

You most likely want:

 transform.position = Vector3.Lerp(position, destination, rate * Time.deltaTime);
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

20 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

Related Questions

Make Lerp or other more fluid or continuous 3 Answers

Using lerp to scale 1 Answer

What is interfering with my Lerp? 1 Answer

Moving multiple objects at same speed 1 Answer

Smooth the Changes in TimeScale, in TimeBending script 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