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 apple741 · Mar 09, 2011 at 11:41 AM · physicsiphonegraphicsoptimization

Can I stop a lerp completely when it gets to 20% of its original value?

I use the code bellow to move images across the screen as seen in this video: http://screencast.com/t/GW9K8bbQcmYj

Is there a way to stop the lerp completely when it gets to say 20% of it's intial value just to make the final stage of the sliding slow down quicker - as I intend to make it 'bounce' back to the last full image so that the user is never left with half an image on the screen.

I do like the slide effect when the user stops swiping but after a while it still moves a little even though nothing is visible to the eye it's that small movmement I'm trying to get rid of.

code wrong.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by loopyllama · Mar 09, 2011 at 04:17 PM

you just need to rewrite your code a little bit.

right now you are lerping a constant amount every update. It is a lot like saying "I want to reach the wall so I will go 50% of the way to the wall every step"...you never quite get there. how is this happening? lerp's 3 argument determines the blend between A and B, with 0 being 100% A, and 1 being 100% B. You are setting the value to four times the delta between frames. I dunno what that is but it is small. So on frame 1 you go some small (practically constant) amount from where you are to your target, then repeat. What you want to do is move from where your swipe STARTED to your target over an ELAPSED time. something like: capture the startposX in a variable when you detect a swipe and the startTime = Time.time of the swipe. Also maybe a boolean hasSwiped. Then in do a if (hasSwiped) so you are not processing if all swipes are complete. in this if(hasSwiped), calc the elapsedTime = Time.time - startTime then do your lerp. something like lerp (startPosX, targetPosX, myScrollingInSeconds / elapsedTime) where myScrollingInSeconds in the time in seconds to lerp from the start pos to the target pos. you will find linear works as advertised and you will probably desire something like SmoothStep. it is tough for me to explain so I hope it made sense.

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
avatar image
1

Answer by Bampf · Mar 09, 2011 at 12:04 PM

A simple way is to use a non-linear version of Lerp. There are a bunch of them in the Unify wiki in the Mathfx script. You'd want one that goes faster during the earlier stage, then spends less time slowing down at the end of the movement. (This is known as an "ease-out".) Try using their Mathfx.Sinerp function in place of your Lerp.

You may also need to adjust the end position calculation as well. Right now it's based solely on speed and time delta. If you multiple it by 0.8 (for example) your object will move faster to start with and then slow down at the end, but only have to go 80% of the way. You may have to play with that and/or the speed constant until it feels like you want right.

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
avatar image
0

Answer by Statement · Mar 09, 2011 at 01:45 PM

You can add an AnimationCurve that you evaluate instead of the Lerp, or plug it into the lerp.

It's editable in the inspector and allow you to set the values easily. Just add it as a member variable.

var curve : AnimationCurve;

Then use it as such:

var value : float = curve.Evaluate(point);

Just make sure your curve spans the points expected, for example the range 0 to 1.

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

No one has followed this question yet.

Related Questions

Game build works fine in Android but is jittery in iPhone. 0 Answers

Whats the best way to setup a screen like this... 0 Answers

Pitfalls for characer/animations on the iPhone 1 Answer

How to support Retina display 1 Answer

Make objects easier to select 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