Get spline time position from a CFrame

I am working on my spline module better for some VR guns, and I am wondering how to get the closest time position to a CFrame.

This includes positional and rotational values.

Diagram of what I mean:

This is the spline module:
Spline.rbxm (1.6 KB)

took way too long, but I did it!

function NULL_Spline:getNearestTime(cframe)
	local t = 0
	local cf2 = CFrame.identity
	local lowest = math.huge
	
	for ct=0,1,0.01 do
		local cf = self:getPoint(ct)
		local distance = dis(cframe,cf)
		if distance < lowest then
			lowest = distance
			t = ct
			cf2 = cf
		end
	end
	
	return t,cf2
end

“dis() module”

return function(cf,cf2)
	local axis,theta = cf:ToAxisAngle()
	local axis2,theta2 = cf2:ToAxisAngle()
	local da,db = (cf.Position-cf2.Position).Magnitude,((axis*theta)-(axis2*theta2)).Magnitude 
	return da+db, da, db
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.