Odd Line2D Coordinate Issues

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

I am attempting to draw a Line2D from its origin point (0, 0) to the first collision point of a Raycast. The Raycast itself is accurately reporting the coordinates of its first collision, however piping this in to the Line2D produces irregular results. For example, if the Raycast collision point (in global coords) is (1824, 1294.497803), the Line2D’s next point will be drawn at (-797.333496, -66) when using to_local(). What would be causing this behavior? Using r.position and $RailgunRatcast.get_collision.point() produces the same coordinates.

var r = Railgun.instance()
get_tree().get_root().add_child(r)
r.global_position = $RailgunRaycast.get_collision_point()
railgunCharge = 0
$RailgunLine/RailgunLineClearTimer.start(0.25)
$RailgunLine.add_point(Vector2(to_local(r.position)), 1)

I am sure that adding the Line2D to the scene itself instead of a child node of the player character would solve this issue, however I believe that would make working with it more difficult in the future.