Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Credit to stravant
- function clamp(n, bound)
- if n > bound then
- return bound
- elseif n < -bound then
- return -bound
- else
- return n
- end
- function ClosestPointOnPart(point, part)
- local p = part.CFrame:vectorToObjectSpace(point-part.Position)
- local hz = part.Size/2
- local pointOnPart = Vector3.new(clamp(p.x, hz.x), clamp(p.y, hz.y), clamp(p.z, hz.z))
- return part.Position + part.CFrame:vectorToWorldSpace(pointOnPart)
- end
Advertisement
Add Comment
Please, Sign In to add comment