Changing the length won't fully fix the problem. It may look ok for your current camera setup but may appear off as soon as you change zoom, fov or viewing angle.
If I understood correctly, you want to place objects on the ground where the mouse cursor is. The actual 3d location you're after is the point that represents the mouse pointer perspective (un)projection onto the ground plane.
var ray_origin = camera.project_ray_origin(event.position);
var ray_direction = camera.project_ray_normal(event.position);
var plane = Plane (Vector3.UP, 0.0) # horizontal plane at y=0
var projected_mouse_position = plane.intersects_ray(ray_origin, ray_direction)