Maybe someone will correct me, but I don’t think there’s any built-in method to do this. I think you’ll need to do a bit of work yourself.
Are your targets always rectangles (as in your image)?
If so, you could probably use Godot’s geometry functions do the underlying math for you. Maybe something based on Geometry2D.get_closest_point_to_segment()(Docs here)
You could pass in each of the 4 segments making up the target rectangle. That’ll give you the closest point on each of the 4 segments. The one closest to your original point is the one you’re after…