Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Nov 21, 2015 at 04:14 PM by Robxd0 for the following reason:

I found out the problem.

avatar image
0
Question by Robxd0 · Nov 21, 2015 at 01:21 PM · c#transformlerp

Problem with Mathf.Lerp

Hello everyone, I'm trying to lerp between two values.

         if(gameObject.transform.position != endPos)
         {
             
             float currentDuration = Time.time - lerpStartTime;
             float journeyFraction  = currentDuration / totalDistanceToDestination;
             gameObject.transform.position = new Vector3(Mathf.Lerp (startPos.x, endPos.x, journeyFraction * 2f), gameObject.transform.position.y, gameObject.transform.position.z);
             print("posX: " + gameObject.transform.position.x);
         }
         else if(gameObject.transform.position == endPos) { lerping = false; alreadySwiped = false;}

This is the code i'm using. So, the problem is, it never gets tot the end of the "endPos.x".

For a better understanding, here is the output of the print in the first if statement:

 starPos = (24.3, -22.5, -11.7)
 endPos = (31.9, -22.5, -11.7)
 
 posX: 30.9175
 posX: 31.33167
 posX: 31.74583
 posX: 31.86094
 posX: 32.16732  -- Here it goes over the maximum value.
 posX: 31.86094  -- Here it goes to the final value again.
 posX: 32.58005  --  Again, but this time the number is bigger.
 posX: 31.86094
 posX: 32.99336
 posX: 31.86094
 posX: 33.40636  -- And it just goes on like this, and never stops.


 

I'm out of Ideas. I tried Vector3.Lerp too, the output is the same. I'm happy for every suggestion you may have. 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 meat5000 ♦ · Nov 21, 2015 at 03:59 PM 0
Share

Look again at the t factor for Lerp (Its the same for all versions).

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

Then search for "Easing Lerp" and see that its the same but used slightly differently.

Easing lerps generally never reach the end and rely on a changing endpoint rather than modifying t. In this case t affects the size of the step taken.

1 Reply

  • Sort: 
avatar image
0

Answer by Robxd0 · Nov 21, 2015 at 04:13 PM

Oh, thanks that was useful. However, I found out why it was bouncing between that two values at the end. I had accidentally implemented the script twice on the same object... Awkward mistake, but thank you anyway :).

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

Follow this Question

Answers Answers and Comments

35 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 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

Coroutine: delay transform rotation but start transform movement immediately 2 Answers

Movement and Direction script bugging out 1 Answer

If statement not getting called after Lerping a Scale 1 Answer

Lerping Camera Between Two Points 0 Answers

Object moving chaotically using lerp and repeating. 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