3

I am trying to change the length of my line renderer over time using DOTween.

LineRenderer myLineRenderer = GetComponent<LineRenderer>();
myLineRenderer.SetPosition(1, new Vector3(x, 0, 0));

This code snippet changes the position of myLineRenderer to x. How can I use DOTween to set the position gradually to x over 1 second?

Patrick Klug
  • 14,056
  • 13
  • 71
  • 118
Ogen
  • 6,499
  • 7
  • 58
  • 124

2 Answers2

2

Why not just tween it yourself?

float x = 0f;

IEnumerator TweenLinerenderer()
{
    while(x <= 1f)
    {
        myLineRenderer.SetPosition(1, new Vector3(x, 0, 0));
        x += Time.deltaTime;
        yield return null;
    }
    x = 0f;
}
maraaaaaaaa
  • 7,749
  • 2
  • 22
  • 37
  • I wanted to use DOTween to save code but I guess you can't do it. This works though, thanks. – Ogen Jun 10 '15 at 03:03
  • not a really good answer... Dotween has a lot of options like Easing and other tools that you should implement on your own otherwise,. – MatterGoal Sep 22 '21 at 10:28
2
LineRenderer l = GetComponent<LineRenderer>();
DOTween.To(() => l.GetPosition(lineRenderPoint), (x) => l.SetPosition(lineRenderPoint, x), new Vector3(0, 0, 10), 10).Play();

Where lineRenderPoint is the point you want to move.

createproblem
  • 1,542
  • 16
  • 30