Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 cuiBono · Jun 26, 2018 at 07:24 PM · vector3performancetransitionsvector3.lerplerping

Lerping Issue

I've implemented the lerping method to smoothly transition the position of a transform from one position to another, to have that "decelerating" effect.

From my understanding, the way this is accomplished is by moving a certain percentage (the "t" parameter) of the distance between the two positions on every update, then updating the initial position (the "a" parameter) to the position moved to, and repeating. This way, on every update, the transform moves closer to its final position by a smaller amount, the "speed" of movement appears to be decreasing, and thus the smooth decelerating effect.

I have an object that calls a coroutine that carries out this transition up into my view. Immediately after the subroutine call, the script checks for input. If a there is user input, a 2nd function is called on every update to carry that same object downwards out of the scene at a certain speed.

Here's my problem: If the user inputs before the coroutine finishes executing, and enables the 2nd function, then the coroutine never finishes executing. This is because the coroutine is applying a upwards, positive speed and the 2nd function is applying a downwards, negative speed, so the object becomes stationary. This is not what I want.

Now, I could wait until the coroutine finishes before checking for user input, BUT, because of the method I'm using (described in the second paragraph), there's a point in time where the transform appears to have reached its destination, or is close enough for the user to have understood its use and attempted to interact with it, but is actually still lerping; still moving by some very small amount. At this point the user would probably want to interact with the game, but wouldn't be able to if the game is waiting for the subroutine to finish. This is the case even if I stop the lerping when the distance between the transform's position and the final position is a very tiny amount; the deceleration time isn't predictable in this way.

So, a potential solution I found is to use lerp based on a sine function, as this could provide that same decelerating effect. The problem with this is that a call to the sine function is more expensive than just using a fixed value for the t parameter of the lerp... I'm not sure how much more expensive, but it's definitely more predictable.

Is there any other solution to this? Is this method of lerping just not appropriate for these kinds of UI dependent transitions? Thank you!

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 ahstein · Jun 26, 2018 at 08:25 PM

If the user interacts with the object, can you just set some flag to stop the lerp early?

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 cuiBono · Jun 26, 2018 at 08:33 PM 0
Share

Tried that, but I'm afraid of the user accidentally interacting with the object without the lerp being fully completed... The action that I'm actually looking for is the user tapping the screen, so that the 2nd method I mentioned is called repeatedly. If the user accidentally taps before the lerp is completed, then the 2nd method will start updating the object while it's in a position it's not intended to be in.... does that make sense?

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

126 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

Related Questions

why one works, the other does not 2 Answers

Child GameObject is aligned to world axis and not the parents axis (UPDATE) 1 Answer

Camera Controller to Player Position Conflict 1 Answer

Unity smooth following 2D camera not working properly on different resolutions 0 Answers

Getting Vector3 in between two given Vector3 after given Distance. 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