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 sethuraj · Feb 24, 2014 at 10:43 AM · timelerpsync

Lerp time and movement not in sync

I'm using vector3.Lerp to move from one position to another,but the lerp time and moevement are not in sync as lerp varies from 0 to 1.

Here's my code

 Vector3 Target_Pos=new Vector3(0.18f,0,0);
 float LerpTime=0.0f;
 float LerpSpeed=10.0f;
 
 void Update()
 {
    if(LerpTime<1.0f)
    {
       transform.position=Vector3.Lerp(transform.position,Target_Pos,LerpTime);
       LerpTime=Time.deltatime*LerpSpeed;
    }
    else
    {
       Debug.Log("Lerp is finished");
    }
 }

But the object reached at position 0.18f in X before LerpTime reaching 1.0f.The object finished interpolation at a time near 0.05 to 0.1f,but the log will out only when the LerpTime variable reaches 1.0f which is areound 10 to 20 seconds after movement is finished.I need to log the exact time when the object reached its target position

Any help....?

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 benni05 · Feb 24, 2014 at 10:49 AM

Your LerpTime needs to approach 1f but it stays the same all the time, namely Time.deltaTime*0.18f (just considering the x component). Since deltaTime is almost a constant as well (i.e. 0.02f, the amount it takes to render the last frame).

Change to:

 LerpTime += Time.deltaTime;

The transition (Lerp) will then take approx. 1 second. If you would like to speed this up, multiply by a factor, i.e.

 LerpTime += Time.deltaTime * 4f;

which makes it 4x as fast, leading to a duration of 0.25 seconds.

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 benni05 · Feb 24, 2014 at 10:55 AM 0
Share

Just to make sure you understood Lerp. The function will return the first parameter (in your case transform position) if LerpTime is zero and the second parameter if LerpTime is >=1f. And a value inbetween those parameters if >0 && <1f. Also, do not use transform.position as first parameter because this is not a constant value. Store the transform.position of your object in a variable before starting to Lerp, use this variable as the fist parameter and then you get a defined movement as described above.

avatar image sethuraj · Feb 24, 2014 at 11:16 AM 0
Share

It worked.I didnt knew that the first and second parameter of Lerp should be constant.Replacing transform.position with a pre captured constant position value did the trick.

Thanks a lot.. Cheers.. :-)

avatar image benni05 · Feb 24, 2014 at 11:19 AM 0
Share

Ok, great. It doesn't have to be a constant. But if you are using the transform.position you are at the same time changing it easily gets confusing and you cannot exactly configure the speed in the way described. Thanks for accepting the answer. Cheers.

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

Lerp - Time Remaining 1 Answer

Synchronize object positions 1 Answer

Move Transform to Target in X seconds 3 Answers

Lerp to position, after a while come back, problem occured using Coroutines 1 Answer

Controlling duration of Color.Lerp in seconds 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