0 votes

I would like to draw Bezier curves with a start, end, and a couple of control points (so Cubic Bezier curves).

As a part of this, I'll need to be able to ascertain whether the mouse is over the line (so that it changes color, indicating to the user that it is selectable).

I know the geometric Line primitive has no width - so I assume this is to be done with an Area2D which has a defined CollisionPolygon2D which closely follows the line except slightly wider (to create an actual area), then move a "hidden" object under the mouse which would trigger the line?

That sounds very convoluted and I was wondering if that's the right way or if there's a better way. Thank you!

in Engine by (17 points)

1 Answer

+1 vote
Best answer

Hi,
Just get the code from here
https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
Convert it to gd script
Check the result against a virtual width

If distance_to_line(px,py,x1,y1,x2,y2) < my_proximity:
    do_fancy_stuff()
by (4,048 points)
selected by

Thank you very much, this is awesome! I will use this to calculate the mouse proximity :)

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 Frequently asked questions and 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.