Use the mouse positon (or as godot calls it translation) read this
InputEventMouse has global_position and position properties, both returning a vector2. Use this data as a target for the next position your sword has to follow. Using func _process(delta): so that it’ll constantly move towards the mouse.
This doesn’t seem to work when you have a camera that rotates around an enemy using look_at() which is what I’m doing, the sword just goes somewhere completely different.
I ended up finding a solution from this link that worked for me:
func _input(event):
if (event is InputEventMouseButton):
if (event.pressed == true and event.button_index == 1):
var camera = get_node("Camera")
var from = camera.project_ray_origin(event.position);
var to = from + camera_project_ray_normal(event.position) * distance_from_camera;
# Apply the position to whatever object you want (we'll assume a node named "Cube")
get_node("Cube").global_transform.origin = to;