local function B(B)if B.Magnitude==0 then return Vector3.zero end return B.Unit end return function(G,R,p)debug.profilebegin("\068\105\115\116\097\110\099\101 \067\111\110\115\116\114\097\105\110\116")local r=p.Bones[G.ParentIndex]if r then local p=G.FreeLength local c=B(R-r.Position)local j=r.Position+c*p debug.profileend()return j end debug.profileend()return end
local function SafeUnit(v3)
	if v3.Magnitude == 0 then
		return Vector3.zero
	end

	return v3.Unit
end

return function(self, Position, BoneTree)
	debug.profilebegin("Distance Constraint")
	local ParentBone = BoneTree.Bones[self.ParentIndex]

	if ParentBone then
		local RestLength = self.FreeLength
		local BoneDirection = SafeUnit(Position - ParentBone.Position)

		local RestPosition = ParentBone.Position + (BoneDirection * RestLength)

		debug.profileend()
		return RestPosition
	end

	debug.profileend()
	return
end
