Is there a faster way to find the closest line to a center

Godot Version

4.5.1.stable

Question

hi, i made this simple math calculation to find the closest point in a specific radious (minDistance) around a player for path finding (agent = enemy, target = player)

var directionToCenter: Vector2 = agent.global_position - target.global_position
var magToCenter: float = directionToCenter.length()
var desiredTarget: Vector2 = Vector2(target.global_position.x + directionToCenter.x / magToCenter * minDistance,target.global_position.y + directionToCenter.y / magToCenter * minDistance)
agent.findPathToTarget(desiredTarget)

i was wondering if there is a faster way to do this (if it makes a noticeable difference)

I’m not sure what you need. The closest line would simply be:

global_position.direction_to(target.global_position)

Multiply it by the distance you need I guess?