Guest User

Untitled

a guest
Feb 21st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. --Credit to stravant
  2. function clamp(n, bound)
  3. if n > bound then
  4. return bound
  5. elseif n < -bound then
  6. return -bound
  7. else
  8. return n
  9. end
  10. function ClosestPointOnPart(point, part)
  11. local p = part.CFrame:vectorToObjectSpace(point-part.Position)
  12. local hz = part.Size/2
  13. local pointOnPart = Vector3.new(clamp(p.x, hz.x), clamp(p.y, hz.y), clamp(p.z, hz.z))
  14. return part.Position + part.CFrame:vectorToWorldSpace(pointOnPart)
  15. end
Advertisement
Add Comment
Please, Sign In to add comment