Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Woj_Gabel_FertileSky · Jun 25, 2011 at 03:44 PM · vector3lerpsmooth

Smoothing motion with vector3 lerp

Hi there.

Ok, so the answer is in here: Oscilating variable

None of the Vector3.Lerp, SmoothDamp and pingPong solved my problems.

I have a simple question about lerp. I tried to make my gameobjects float(from transform.position.y to transform.positiony-1 and back again), but cant get it to work using unty's reference code from the Vector3.lerp page. In my scene i have some instantiated cubes, theat i want to float to transform.position.y -1, but it just goes to -infinite on y axis. To fix that i tried to declare a new Vector3 of this object in the Start function. Problem with this is that objects with this script are jumping rapidly in one position. Why is that? I think i overlooked something very basic here, or im trying to do this with wrong kind of code. My code(basically the reference code):

 var start: Vector3;
 var end: Vector3;
 
 function Start () {
     start = transform.position;
     end =Vector3(transform.position.x,transform.position.y-10,transform.position.z);
 }
 
 function Update () {
 
     var distanceTo = start - end;
     var smooth = 1.0;
 
         transform.position = Vector3.Lerp(start,end, Time.deltaTime* smooth);
 
 }


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
2

Answer by benni05 · Jun 25, 2011 at 04:03 PM

There is one crucial difference to the reference code: the latter one uses Time.time not Time.deltaTime.

You could also try this:

 transform.position = Vector3.Lerp(start, end, Mathf.PingPong(Time.time, 1.0));

for a forth and back movement.

Ben

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 ckfinite · Jun 25, 2011 at 04:05 PM 2
Share

Oops, I missed that. I am so used to seeing Time.time there. Also, with the ping pong, you could also use $$anonymous$$athf.Sin(Time.time)/2+.5f if you want a smoother transition.

avatar image
0

Answer by ckfinite · Jun 25, 2011 at 04:03 PM

Set your smooth variable to a very small number, like .01. Why? Well, Vector3.Lerp runs from 0 to 1, between the two position where 0 is the start and 1 is the end. This means that if you feed just Time.time, in seconds, it will move that distance in 1 second, which is a shorter amount of time than most people think.

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 Woj_Gabel_FertileSky · Jun 25, 2011 at 04:20 PM

Ben 36: Thanks for the PingPong. I now dont have to use if's. And the Time.time did the trick.

Unfortunately its not lerping. It just going to -1 and back again, without smoothing. Same is with Vector3.SmoothDamp.

It all have the same problem of not lerping, or jumping in one place.

And when using code from unity reference i could drag object with script in the scene viewer, but now i cant. I hope that wont be a problem when i want to use force on those objects...

Comment
Add comment · Show 2 · 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 benni05 · Jun 25, 2011 at 04:26 PM 0
Share

Please use comments ins$$anonymous$$d of creating new answers ;-) Apart from that, please try Vector3.SmoothDamp function, this might be the solution for you. But there the time parameter is Time.deltaTime again, be aware (it's optional).

avatar image Woj_Gabel_FertileSky · Jun 25, 2011 at 04:54 PM 0
Share

Well, SmoothDamp does the same as first script - object just jump in one position. Tried all kind of values.

Its really weird that the basic function is so messed up when vectors are referenced from start function.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

moving between two points over time 1 Answer

How to smooth my camera (Vector3.Lerp) 0 Answers

How would I smooth out a Quaternion? 2 Answers

smoothly change position of an Object 1 Answer

Issues with Lerps 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