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 darthbator · Oct 08, 2012 at 12:54 AM · lerpvector3.lerp

Correctly using Vector3.Lerp to move object around

So I've been playing with using Vector3 to move things around in my environment (primatives, the camera etc). I was originally having an issue where my objects just NEVER quite got to where they where supposed to be. They would approach the destination and then they would SLOWLY start to crawl.

I've been looking into this for a while and using the docs I found out that the t value in the Vector3.Lerp method was clamped between 0-1 where 0=to and 1=from. Using that logic I figured that my previous Lerp attempts where simply moving an almost imperceptible measure every frame towards the end. I wrote something that looks like the following that works much better. However I noticed that the object seems to reach it's destination long before my position float hits 1. Why is this?

     void Update () {
         
         if (pos < 1) {
             moveIt();
         }
         tgui.text = pos.ToString();
     }
     
     void moveIt () {
         transform.position = Vector3.Lerp(transform.position, new Vector3(target.position.x + offset, 3, target.position.z), pos);
         pos += lerpSpeed;
     }
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 Mario Jojo · Oct 09, 2012 at 10:40 AM 0
Share

by using this line you are making it go from a = a -> b! so it will never reach the end! it will keep lerping between a -> b as a never gets to a! a is always the start! try using a temp vector! start()

{

TempVector = transform.position;

}

update

{

transform.position = Vector3.Lerp(TempVector, new Vector3(target.position.x + offset, 3, target.position.z), pos);

}

2 Replies

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

Answer by Eric5h5 · Oct 08, 2012 at 01:49 AM

http://answers.unity3d.com/questions/14288/can-someone-explain-how-using-timedeltatime-as-t-i.html

http://wiki.unity3d.com/index.php?title=MoveObject

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 Aqib_ch_dev · Mar 15, 2021 at 06:30 AM

 public float rate = 0.1f;
 public int sign = 1;
 public Vector3 posA;
 public Vector3 posB;

 private void Update()
 {
     rate += (sign) * Time.deltaTime;
     transform.position = Vector3.Lerp(posA, posB, rate);
     if (transform.position == posA || transform.position == posB)
         sign *= -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

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

make my gameobject lerp between points more smoothly 0 Answers

I'm using TRANSLATE but want to use LERP. C# 2 Answers

Computation of Vector3.Lerp, does it check for change? 3 Answers

vector3 lerp based on 2 different floats/axes? 1 Answer

Vector3.Lerp move weapon up to players face 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