• 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 TurboHermit · Jul 30, 2018 at 02:03 PM · animationtimelerppathlerping

Lerp waypoint path easing

Hey folks, I'm making a path animation tool using waypoints and I could use some help with the math. It's set up like this: you feed it a fixed amount of time for the animation to play and finish, for example 3 seconds. The script iterates through the waypoints (a vector3 array) and Lerps a transform between the current and next waypoint. The Lerp speed is calculated by dividing the total animation time with the distance between the designated waypoints, resulting in a constant speed over the entire array.

Now I want to use an AnimationCurve or any other slightly customizable method to easy the ENTIRE animation in and out. The problem is that an AnimationCurve works very well with a single Lerp as time value, but is harder to stretch over all these tiny Lerps which use a constant, calculated speed. Here's a snippet to give you an idea:

 currentSpeed = animationTotalTimeInSeconds / Vector3.Distance(path[currentPoint], path[nextPoint]);
 waypointTime += Time.deltaTime * currentSpeed;
 
 targetTransform.position = Vector3.Lerp(path[currentPoint], path[nextPoint], waypointTime);

Just multiplying the currentSpeed with an AnimationCurve.evaluate alters the SPEED, but I still want the total animation length to be the same, which is TIME.

Any ideas on how to fix this or faced a similar problem?

Thanks.

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 TurboHermit · Aug 01, 2018 at 02:23 PM 0
Share

I just realized the animationTotalTimeInSeconds isn't even time in seconds but also some kind of speed. The case in which I was using it just happened to be around the same amount of time as I was putting in it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bubinga_Studios · Aug 01, 2018 at 03:36 PM

Well Lerp is more of a position based timeline, so if you are trying to have a constant value, you may want to make your character look at the next point and move by a fixed amount of time using something like this.

 transform.LookAt(path[nextPoint]);
 transform.Translate(Vector3.forward * animationTime * Time.deltaTime);

I am having a little bit of trouble understanding your entire question, so if I didn't answer correctly, you can give me a bit more insight on your end achievement.

Hope this helps!


Comment
Add comment · Show 1 · 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 TurboHermit · Aug 01, 2018 at 06:28 PM 0
Share

Hey thanks for your answer. I'm avoiding using Translate or $$anonymous$$oveTowards or any other movement method because I use Lerp info for other stuff as well.

$$anonymous$$y question has gotten a bit convoluted but basically what I'm asking is how would you smooth/ease a "speed" variable, but keep the entire thing a constant "time". It gets complex because it's multiple tiny Lerps that make up a single animation.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Animation Stop and Stay 1 Answer

Animate Object Related to Camera Position 1 Answer

Timing multiple events at certain times? 1 Answer

Animation play 1 Answer

How can I Lerp the Rotation of my Game Object to my Mouse Pointer? 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