- Home /
Lerp tutorial missing variable value
Just chugging away through the tutorials...
Does anyone else have problems with this LERP tutorial?
More specifically, making the light lerp transform work with the JavaScript code.
transform.position = Vector3.Lerp(transform.position, newPosition,Time.deltaTime);
Works fine, but
transform.position = Vector3.Lerp(transform.position, newPosition,Time.deltaTime * smooth);
Doesn't work. Smooth doesn't seem to have a value assigned to it; but I may be wrong. In which case it's time to check out scope...
If you haven't declared the variable then do it and assign a value to it, like var smooth = 5;
Answer by robertbu · Jan 14, 2014 at 05:38 PM
At the top of the script you should see something like:
var smooth = 2.0;
'smooth' will control the speed of the Lerping(), though 1) the speed is not linear, and 2) this use of Lerp (while common), is not standard and is not really Lerping since the 'L' in Lerping is for 'Linear'. It works by moving approximately the same percentage towards the goal each frame. As the distance drops, the same percentage gives ever decreasing distances for the movement.
yepp, my comment 3 weeks ago on that video was ignored... A more recent video with errors got replaced, but nobody seems to care for those old ones anymore.
Followup: In the script below the video, smooth is declared as:
public var smooth;
The expectation is that the value would be set in the Inspector. Without initialization, the value would be 0, and the code would fail.
I thought that was the case. Would it not be worth updating the scripts so that they work??
I have no input with Unity. It would be better if the script assigned a meaningful default value.