How do I get the closest point on a ray?

I need to get the closest point on a ray from another point. Basically its the Ray:GetClosestPoint() function but Im not using the legacy ray. I need a simple and easy to understand formula. I dont understand all the math on google beacuse I havnt even learnt it in school.

I am using it for lag compensation for my raycast gun/

Read up on the Hit Detection section, RaycastResult.Instance.

thats not What i wanted. I need to get the closest point of a vector3 to a ray

nevermind guys the formula i have is already working
here it is for those that need it:

local function GetRayClosestPoint(Origin, Direction, Point)
	local A, B = (Origin - Point), Direction.Unit

	local V = A - A:Dot(B) * B.Unit

	return Point + V
	
end
4 Likes