I have tried this previously , just put this script on a camera and read the position of the clickpos variable and it should work ... and make sure whatever mesh you are using it should have a static body child or parent , and a collision mesh , because you need colliders to make it work
extends Camera
var ray=RayCast.new()
var clickpos= Vector3(0,0,0)
func _ready():
add_child(ray)
ray.enabled=true
func _input(event):
var clicked = (GetMouseClick(event))
func GetMouseClick(event):
var distance_from_camera = far
if event is InputEventMouseButton:
var from = project_ray_origin(event.position);
var to = from + project_ray_normal(event.position) * distance_from_camera;
ray.cast_to = to-global_transform.origin
if (event is InputEventMouseButton):
if (event.pressed == false and event.button_index == 1): #check if Left Click is released
if ray.is_colliding():
var raypoint = ray.get_collision_point()
return (raypoint)