Signal for OnMouseEnter for Line2D?

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

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!

:bust_in_silhouette: Reply From: klaas

Hi,
Just get the code from here

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()

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

learning_for_godot | 2020-08-25 09:41