I feel like you need to give more context on what exactly you try to achieve.
Suppose you have a tower defense game, and your tower should lock onto and enemy, you can simply use the look_at(target) method. You will have to set the target variable accordingly for it to work.
e.g.: you cann ad an area2D which signals to the tower when a body has entered/left the area2D. then you can get all potential target via get_overlapping_bodies(). Then you can write your custom sorting function to find the desired target.
Hope i could help