how to raycast from the mouse godot code example
Example: godot get mouse position raycast
var mouse_pos = get_viewport().get_mouse_position()
var from = self.project_ray_origin(mouse_pos)
var to = from + self.project_ray_normal(mouse_pos) * ray_length
var space_state = get_world().get_direct_space_state()
var results = space_state.intersect_ray(from, to)
if results.size() > 0:
return results["position"]