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 CeejayZSmith · Oct 28, 2012 at 07:51 PM · vector3vector3.lerpunderstand

Can someone help me to understand what vector3.lerp does and can be used for

ive seen a tutoiral on youtube on a smooth gun movement script what the script does is every time i turn left of right the gun is alittle slower then catches up to the camera to make ait look more realistic but i want to know how this actually works to maybe implement it somewhere else

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

2 Replies

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

Answer by fafase · Oct 28, 2012 at 08:05 PM

 transform.position = Vector3.Lerp(start, to, t);

It is an interoplation between start and to by t.

In human word, it means you take the start(transform.position) and you look at to (target.position). Then you move the object by the amount of t. If you give t= 1 it moves suddenly from start to to. If you give 0.5 it will move 1/2 each frame.

Often it is used like this:

 function Update(){
     transform.position = Vector3.Lerp(transform.position, target.position, Time.deltaTime);
     }

If there would be 10 m between transform(0) and target(10) and deltaTime is 0.2 (20%) then you get:

  1. 20% of target-transform (10-0) = 2m so transform = 2

  2. 20% of target-transform (10-2) = 1.6m so transform = 3.6

  3. 20% of target-transform (10-3.6) = 1.28m so transform = 4.88

  4. And so on

Hopefully you get the idea.

Comment
Add comment · Show 9 · 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 Xroft666 · Oct 28, 2012 at 08:07 PM 0
Share

arghh, this one is yours )

avatar image CeejayZSmith · Oct 28, 2012 at 08:10 PM 0
Share

i understand everything i think except whats t? and how to i change it?

avatar image fafase · Oct 28, 2012 at 08:13 PM 0
Share

t is the percentage you want to interpolate. So you either give it a value between >0 and 1 (0 would mean no movement so anything greater than 0). 1 is full movement at once. By giving any value in between you interpolate each frame to the next value. Note that you actually never reach the target since you always move of a percentage of the distance between. Just like limits in algebra, you get so close but never reach.

avatar image CeejayZSmith · Oct 28, 2012 at 08:15 PM 0
Share

how do i change the value of t?

avatar image fafase · Oct 28, 2012 at 08:23 PM 0
Share

What do you mean? you give it a value that is it...between >0 and 1 (0 would mean no movem...hold on I said that already. I gave Time.DeltaTime because it is a small value but give what you want between >0 and 1 (0 would mean Grrrrhhhh.

Show more comments
avatar image
0

Answer by Xroft666 · Oct 28, 2012 at 08:06 PM

Lerp - is short version of Linear Interpolation

What it does: it takes 2 vectors and an float variable from 0f to 1f.

If you give 0 then the function returns the first given vector, if you give 1f it returns the second vector. If you give for instance 0.3f, the function returns (interpolated \ crossfaded \ blended) vector of those two, where are 0.3 parts of the first one and 0.7 parts of the other.

Example: Lerp( (10,0,0), (0,10,10), 0.5f ) = 5,5,0

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

12 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

Related Questions

How the heck does Mathf.Lerp work? 2 Answers

How to move character a certain amount? 1 Answer

Lerping Issue 1 Answer

Vector3.Lerp move weapon up to players face 2 Answers

Add a Vector3 to the rotation of an obj and have it behave with logic! 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