Vector3 Lerp not moving smoothly. Snapping from 0 to 1

Hi everyone,

I’m trying to make an object rise through the floor of my game, and to accomplish this I’m trying to use a Vector3.Lerp. Unfortunately, no smooth movement happens. The object simple snaps to its end position immediately. Here is my code:

var animationDuration : float = 2;
var time : float = 0;
var damper : float = 1.5;

function Update()
{
	Rise();
}

function Rise()
{
	var startPosition : Vector3 = this.transform.position;
	var endPosition : Vector3 = Vector3(this.transform.position.x, (this.transform.position.y + 10),
	this.transform.position.z);
	
	yield WaitForSeconds(2);
	
	while (time < animationDuration)
	{
		time += Time.deltaTime;
		this.transform.position = Vector3.Lerp(startPosition, endPosition, time * damper);
	}
}

Your while loop has no yield in it, so it will finish in one frame. Also, you’re calling Rise() every frame in Update. Just call it once in Start instead. (You don’t need “this.transform”, just “transform” is fine since it already refers to the object’s transform component.) See here for a basic move routine script.

–Eric

thank you so much for your help! It solved the problem perfectly!!
:smile: