- Home /
Lerp Never Reaches Target
LineRenderer lineRend;
public Transform startPos;
public Transform endPos;
public float speedOfDecrease;
bool isShrinking;
private Vector3 endPosExtendedPos;
public DrawLineNote()
{
isShrinking = false;
}
public void Awake(){
}
// Use this for initialization
void Start () {
lineRend = GetComponent<LineRenderer> ();
endPosExtendedPos = endPos.localPosition; lineRend.SetPosition (0, startPos.position);
lineRend.SetPosition (1, endPos.position);
}
public void Shrinking(){
this.isShrinking = true;
Debug.Log ("what the heck");
}
public void NotShrinking(){
this.isShrinking = false;
}
// Update is called once per frame
void Update () {
lineRend.SetPosition (0, startPos.position);
lineRend.SetPosition (1, endPos.position);
if (this.isShrinking) {
Shrink ();
}
}
public void Shrink(){
//The line starts shrink
endPos.localPosition = Vector2.Lerp (endPos.localPosition, startPos.localPosition,Time.deltaTime * speedOfDecrease);
}
Everything works fine its just when I leap the line, it never reaches the destination I want it too, it decreases exponentially so it goes fast then slows down. I want it to decrease at a constant rate
Answer by LilGames · Mar 30, 2018 at 07:14 PM
Follow the example shown here: https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
Answer by Rygaran · Mar 30, 2018 at 08:27 PM
Lerp will give you a smooth shrinking, if you want a constant decrease, just do: endpos += (startpos - endpos ).normalized * multiplier this will make endpos get closer to startpos by a distance of multiplier
Your answer
Follow this Question
Related Questions
Linear interpolation crash 0 Answers
How to make a Line Renderer follow the target without delay ? 3 Answers
LineRenderer (strange bug) 1 Answer
Get positions at equal intervals between two Vector3 3 Answers