How to change Line2D width at individual points

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Drawsi

I used $Line2D.width but it changes the whole line while $Line2D.width_curve is a mess with confusing documentation.

I just want to be able to change the width of a line at individual points of the said line thru code.

Any input will be helpful!

Drawsi | 2023-02-09 17:01

:bust_in_silhouette: Reply From: zhyrin

There is no provided way to achieve what you are describing*.

If you are willing to do so some manual line drawing, you best bet is using CanvasItem.draw_line() for each segment (all Node2D inherint form CanvasItem).
Another solution might be to have a different Line2D node for each segment where the width changes.

*Actually you can build the width_curve programatically and that way you can create a curve that changes the width exactly at the points you wish. You seem to want to avoid working with the curve solution but I encourage you to try, maybe it’ll become useful experience for a later day .

With curve I have add_point(position: Vector2, left_tangent: float = 0, right_tangent: float = 0, left_mode: TangentMode = 0, right_mode: TangentMode = 0)to add a new point but I don’t understand what the vector2 does exactly, I’m assuming it’s choosing the position of the point with x and a width value with y although I haven’t been able to make that work.

line.width_curve.set_point_value(1, ssize)

This is what I’m currently using but it is not giving me any useful result.

Drawsi | 2023-02-13 14:53