Struggling to Understand Lerps

So, what I’d like to do is walk up to a door, and hit a key and have the door open (open programatically - not with a built in animation). So the script I’m using includes:

function Update () {
	if (instructionsVisible  Input.GetKeyDown(KeyCode.O)){
		OpenDoor();
	}	
}

function OpenDoor(){
		Debug.Log("I'm opening door");
		leftDoor.transform.rotation = Quaternion.Lerp (from.rotation, to.rotation, Time.time * 1);
	}

Why doesn’t this work?

OK I must confess I don’t know how to do it with Lerp. HOWEVER, we were able to successfully do a door opening script as follows. Actually there are two scripts, one to place on the object to open, and one to serve as an “open button”. Hope this is useful.

≥≥≥≥≥≥ Code for button begins here ≤≤≤≤≤≤≤

≥≥≥≥≥≥ Code for door to rotate begins here ≤≤≤≤≤≤≤

Lerp returns a value immediately, it doesn’t animate anything. That’s up to you to do. Time.time * 1 doesn’t make any sense either; aside from * 1 being useless, the third parameter is between 0 and 1. See here for some basic examples of lerping.

–Eric

To add onto what Eric was saying, lerp is just a math function that returns a value based on the three inputs. Here’s an example, this will return 2.5…

Debug.Log(Mathf.Lerp(0, 5, 0.5));

Because you’re doing a linear interpolation between 0 and 5 halfway between the numbers.

Debug.Log(Mathf.Lerp(0, 5, 1.0));

This returns 5, because you’re interpolating all the way between the two numbers.

The reason it’s used for animation is because you can do this…

transform.position = Vector3.Lerp(start.position, end.position, Time.deltaTime);

If you put this in an Update() function, this will move the object between the start position and end position.

The problem with Lerp is in cases like this…

transform.position = Vector3.Lerp(transform.position, end.position, Time.deltaTime);

Notice the difference? Instead of using a fixed transform for the starting position, we’re using the position of the object being Lerped. This means that when the object is far away, it will move much faster towards the end position, and when it gets closer, it will greatly slow down.

Hope I’ve been making this clear, I know I had a bit of trouble with lerps when I first started out, just want to make it a bit easier for you.

Thanks much for the advice all. It’s starting to get a little more clear there. Eric, I’ll be going over your wiki post multiple times in the coming days. Thanks much!