- Home /
The question is answered, right answer was accepted
How to use Lerp?
I am confused on how exactly to use the Lerp function. I am using the function as Slerp in the following code:
example 1:
selfplace.rotation = Quaternion.Slerp(selfplace.rotation,Quaternion.LookRotation(target.position-selfplace.position),MarManRotateSpeed * Time.deltaTime);
example 2:
selfplace.rotation = Quaternion.Slerp(selfplace.rotation,Quaternion.LookRotation(target.position - selfplace.postition),MarManRotateSpeed * Time.deltaTime);
Please dont post this question in other questions.
http://answers.unity3d.com/questions/230775/character-gravity-problem-character-flies-upward.html
If you are genuinely interested in Lerp , then I apologize .
I created this question because, if you don't remember, @hijinxbassist suggested that I could create the question to both solve some of my problems and contribute to the community. Even if I do not need this for my project, I still want the reference for others to see.
I find this a great explanation: http://answers.unity3d.com/questions/14288/can-someone-explain-how-using-timedeltatime-as-t-i.html?sort=oldest
Answer by Kryptos · Mar 23, 2012 at 08:18 AM
Lerp is a linear interpolation, whereas Slerp is a spherical interpolation.
In the first case, the interpolated point will 'move' from the first to the second argument along the segment formed by these two points.
In the second case, the interpolated point will 'move' from the first to the second argument along the sphere surface which center is calculated so that the first and second argument belong to the arc.
To learn more about Lerp, see http://en.wikipedia.org/wiki/Lerp_%28computing%29.
To learn more about Slerp, see http://en.wikipedia.org/wiki/Slerp
Thank you for the clarification.
Also see @xtplpune's answer for a more technical description.
Answer by xtplpune · Mar 23, 2012 at 08:42 AM
static function Lerp (from : float, to : float, t : float) : float Description Interpolates a towards b by t. t is clamped between 0 and 1.
When t = 0 returns from. When t = 1 return to. When t = 0.5 returns the average of a and b.
JavaScript // Fades from minimum to maximum in one second
var minimum = 10.0; var maximum = 20.0;
function Update () { transform.position = Vector3(Mathf.Lerp(minimum, maximum, Time.time), 0, 0); }
Could you expand on this? What you are saying is vaguely understandable, but I am, for some reason, not completely understanding it. What exactly is a and b? Are they the $$anonymous$$imum and maximum, respectively? Does "clamped" mean changing between?
Thanks for the example script!
This is just a copy from the Unity Script Reference : http://unity3d.com/support/documentation/ScriptReference/Vector3.Lerp.html
yes, this was just a direct link to the reference for you.
Answer by rain · Mar 23, 2012 at 07:44 AM
As far as i know, lerp/slerp must be called in every frame if you want effect.
Btw. are you sure that "selfplace.postition" is an existing property?
I thought I fixed that... I'm changing that line to what it should be. Thank you!