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 $$anonymous$$ · Apr 03, 2013 at 09:11 AM · movementlerpienumeratoroptimizeeasing

Can my lerp-function be optimized?

I have made this little tooltip-gameObject which is supposed to swap in and out new tooltips during the game.

I'm using a standard lerping functionality using a common "EaseOutBack"/"EaseInBack".

Now I could not do a standard Vector3.Lerp over fromPosition and toPosition, since the EaseOutBack routine goes beyond the bounds of from and to. So I had to do this:

     IEnumerator SwapIn()
     {
         
         Vector3 fromPosition = new Vector3(10f, 0, 0);
         Vector3 toPosition = Vector3.zero;
         
         float lerpFactor = 0;
         float duration = 1f;
         float rate = 1.0f / duration;
                 
         float tweenX = 0;
         float tweenY = 0;
         float tweenZ = 0;
         
         Vector3 localPosition = Vector3.zero;
         
         while(lerpFactor <= 1.0f)
         {
             lerpFactor += Time.deltaTime * rate;
             
             tweenX = EasingFunctions.EaseOutBack(fromPosition.x, toPosition.x, lerpFactor);
             tweenY = EasingFunctions.EaseOutBack(fromPosition.y, toPosition.y, lerpFactor);
             tweenZ = EasingFunctions.EaseOutBack(fromPosition.z, toPosition.z, lerpFactor);
             localPosition.Set(tweenX, tweenY, tweenZ);
             
             toolTipsContainer.transform.localPosition = localPosition;
             yield return null;
         }
         
         toolTipsContainer.transform.localPosition = toPosition;
     }

I really think this could be done prettier. In the future I would like to just use generic standard routines all over my game, so I could use an optimal representation of this snippet of logic.

Thank you in advance.

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
0

Answer by Owen-Reynolds · Apr 03, 2013 at 02:22 PM

That isn't doing any more work than a vector3 operation. In other words, the built-in Lerp also does math for x, then y then z. Regular CPUs don't have any special fast way to do things to Vectors all at once (graphic cards do.)

If you just want to save keystrokes, make a function out of those middle four lines: Vector3 easeOutBack(V3 F, V3 T, float pct) { V3 res; res.x=EasingFunction.Ease...(F.x, T.x, pct) ...

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

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

Stopping Vector3.Lerp 3 Answers

Object transported to point instead of moving towards it? 1 Answer

Static Coroutine being called endlessly 2 Answers

Calculating collision behavior while using lerp 0 Answers

Lerping from one position to another in a specific amount of time, no matter the distance 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