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 gottrash · May 12, 2013 at 03:30 AM · lerpslerp

I'm not using Lerp properly

Hi, I'm trying to get a smooth movement with the camera from one spot to another and i used Vector.Lerp for it but it blatently ignores my lerptime i put in it. Although i see that my time variable is getting incremented correctly it just lerps way to fast. What am I doing wrong here?

 public float lerpTime = 12f;
 
 IEnumerator CameraMovementTransition(Transform beginPosition, Transform endPosition)
     {
         isMoving=true;
         
         float time = 0.0f;
         while (time < 1.0f)
         {
             time += Time.deltaTime * (Time.timeScale/lerpTime);
              Debug.Log(time);
             transform.position = Vector3.Lerp(beginPosition.position,endPosition.position,Mathf.SmoothStep(0.0f,1.0f,Mathf.SmoothStep(0.0f,1.0f,time)));
             transform.rotation = Quaternion.Slerp(beginPosition.rotation,endPosition.rotation,Mathf.SmoothStep(0.0f,1.0f,Mathf.SmoothStep(0.0f,1.0f,time)));
             yield return null;
         }
         isMoving = false;
     }
Comment
Add comment · Show 2
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 robertbu · May 12, 2013 at 04:09 AM 2
Share

@sparkzbarca 's solution below will produce an eased movement at the end. It is the most used implementation of Lerp you will find on UA, but it is a "misuse" of Lerp in that Lerp is intended to have the last parameter range from 0 to 1 and produce a linear motion. If you want to fix your code for a s$$anonymous$$dy linear movement make these changes.

Line 8 becomes:

 while (time <= lerpTime);

line 10 becomes:

 time += Time.deltaTime;

Line 12 becomes:

 transform.position = Vector3.Lerp(beginPosition.position,endPosition.position,time/lerpTime);

And you'll make a similar change for the 't' parameter for the Slerp.

avatar image gottrash · May 12, 2013 at 10:52 AM 0
Share

Yes I am misusing the Lerp function intentionally. I'm am trying to get an ease in and out feel for the camera movement. I tested my code in an other scene first and there it worked fine. It's seems that the problem I have lays with my parameters (beginPosition and endPosition. When I use my public variables ins$$anonymous$$d of the parameters it works just fine.. I think my thought process of the Lerp function is still not right..

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · May 12, 2013 at 03:35 AM

you don't understand how the third variable works.

basically your third variable should be

speed * time.deltatime everytime.

or

speed * time.fixedtime if your using fixedupdate.

also your begin position should update every frame.

this is a simple line to lerp a camera.

 float cameraspeed = 10f;
 
 camera.transform.position = vector3.lerp(camera.transform.position, endposition,cameraspeed * time.deltatime);

thats a properly done lerp.

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

15 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

Related Questions

How to use Vector3.Lerp without slow-down 3 Answers

Rotating object around Z axis with lerp/slerp 1 Answer

Moving the player toward a direction 1 Answer

Lerp/slerp to smooth camera 1 Answer

How to make a gameobject look at(rotate) another gameobject smoothly? 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