0 votes

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?

in Engine by (326 points)

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

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:
https://godotengine.org/qa/72842/convert-a-vector2-position-to-an-array-index-in-curve2d

Much appreciated, thank you!

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!

1 Answer

+1 vote
Best answer

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.

by (2,100 points)
selected by

Huge thanks for the answer, estebanmoica. Much appreciated.

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

func draw():
draw
polyline ($Path2D.curve.getbakedpoints(), 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.

Maybe you need .get_curve()?
docs

Huge thanks to both of you! Visibility part solved.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.