Line2D point follow mouse

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

I’m trying to make a point in my line2D follow the position of my mouse. I already have the mouse position working, but I can’t get the point to follow the mouse. If I do $Line2D.set_point_position(0, mouse_pos) it doesn’t follow the mouse, it goes to a seemingly random position.

:bust_in_silhouette: Reply From: ThreeSpark

I solved it! $Line2D.set_point_position(0, get_transform().affine_inverse() * mouse_pos)

I know this is several years late, but I was working on a sample project for myself and came across the issue you were working on here. I think I came up with maybe a simpler or better way to solve the thing you were doing - at least it’s simpler in my head.

Earlier in my code I acquired the laser’s collision point like this:
if rayCast2d.is_colliding():
laser_end = to_local(rayCast2d.get_collision_point())

then when I go to draw the line:

$Line2D.set_point_position(1, laser_end)

pixelmud | 2021-03-26 19:01