Visible and editable Path2D while playing. Is that possible?

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

In play mode a player should see the line of Path2D and be able to edit (not create, but move the handles of pre-made) Path2D. Is it possible at all?

Solved the visibility part. Huge thanks to both of you! Now I need to figure out the “editable” part while in play mode.

Suleymanov | 2020-06-01 14:13

Before continuing to help you, I need to know how to choose a point of the curve according to the position of the mouse. Create a question about it:
Convert a vector2 position to an array index in Curve2D - Archive - Godot Forum

estebanmolca | 2020-06-02 01:30

Much appreciated, thank you!

Suleymanov | 2020-06-12 06:46

With a huge appreciation for your help, can you kindly guide me on how I can add bezier handle controls? Also, function CREATE does create points, though I’d love it to be on the curve just like Path2D editor does, instead of at any place the mouse right-clicked. And also how can I add DELETE function to delete curve points?

I just want to add your solution helped me a lot and hope it will help others on the same boat too. Very highly appreciated!

Suleymanov | 2020-06-12 09:59

:bust_in_silhouette: Reply From: estebanmolca

Path2D has a Curve2D, basically it’s an array of points so
To draw the line you can use in the _draw () function:
draw_polyline ($ Path2D.curve.get_baked_points (), Color.aquamarine, 5, true)

Remember to use update () every time you change any properties of the curve, so that it is updated.

To change position each point look at the curve functions in the help, among other things you have this function:

void set_point_position (idx: int, position: Vector2)

Sets the position for the vertex idx. If the index is out of bounds, the function sends an error to the console.

See Curve2D in godot’s help to see all the features.

Huge thanks for the answer, estebanmoica. Much appreciated.

Suleymanov | 2020-06-01 06:33

I added your suggested part below to have visible Path2D in play mode:

func _draw():
draw_polyline ($Path2D.curve.get_baked_points(), Color.white, 5, true)

but it returns error: invalid get index ‘curve’ (on base: ‘null instance’).

Apparently, there is something I do incorrectly, I need help to figure out what.

Suleymanov | 2020-06-01 07:56

Maybe you need .get_curve()?
docs

RazorSh4rk | 2020-06-01 13:45

Huge thanks to both of you! Visibility part solved.

Suleymanov | 2020-06-01 14:29