Yes, a mathematical question. Yes, there's many clear mathematical solutions. But they seem complex for me. I think, that frequent task in development, so, maybe, there's some built-in simple one-line solutions in Godot? P.S.: Line for me it's a node with an angle, with this angle we have a line building.

Can you provide a specific example? How is the line defined, and how is the point defined?

We have some red wall, we have a blue square. My task is to make a magnet, i.e. red wall should magnetize this, but not in it center(Violet hotline on sketch) - that's logically. I made this to math question and red wall was turned into line(by this 'a' rotation), blue square was turned into point(we interesting it's position).

I need to get a length of segment between point and line, that is perpendicular of line.

Godot includes a math library, that can compute this and most other common functions. You can read the docs if you want to understand some of the math behind it and a potential solution.

https://docs.godotengine.org/en/stable/tutorials/math/vectors_advanced.html

But the easier way is to use the Geometry class.

https://docs.godotengine.org/en/stable/classes/class_geometry.html

The function you want is called "get_closest_point_to_segment"

https://docs.godotengine.org/en/stable/classes/class_geometry.html#class-geometry-method-get-closest-point-to-segment

The first part of this problem is finding the point on the line closest to the given point. Here P is the point in space and A and B constitute the beginning and end of a line. This func returns that point. This is just to give you some insight b/c my use case was a little odd as you see my point P came from the 2d plane while my lines were in 3d space. How I ever got this figured out is beyond me.

func closestPointOnLineSegment(P : Vector2, A : Vector3, B : Vector3) -> Vector3:
	var AB = Vector2(B.x,B.z) - Vector2(A.x,A.z);
	var AP = P - Vector2(A.x,A.z);
	var lengthSqrAB = AB.x * AB.x + AB.y * AB.y;
	var t = (AP.x * AB.x + AP.y * AB.y) / lengthSqrAB;
	t = clamp(t,0.0,1.0)
	var AB3d = B - A
	return A + t * AB3d;
10 months later