I have a line in 3d space defined by two Vector3 endpoints. The line is always restrained horizontally, that is to say the line always has the same Y value. I have a third Vector3 that defines the player’s location and I want them to snap to the nearest place on the line. The part of this process I am having trouble understanding is how to find the closest point on that given line. I tried to use a bunch of trigonometry, but that quickly became a mess. Is their a combination of built in Vector3 commands I can use to find this closest point. The current placeholder systematically checks pre-calculated points on the line, but I think this method is needlessly process intensive.
There’s a good set of 3D Maths functions here which should give you what you want.
ProjectPointOnLinesegment and ProjectPointOnLine are the ones you want.