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);


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.


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.

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…