Advertisement
Jefferz

Untitled

Apr 22nd, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. --returns string (of which side it hit), and CFrame Angle
  2. function DetectSurface(pos, part)
  3. local surface = nil
  4. local pospos = part.CFrame
  5. local pos2 = pospos:pointToObjectSpace(pos)
  6. local siz = part.Size
  7. local shaep = part.Shape
  8. if shaep == Enum.PartType.Ball or shaep == Enum.PartType.Cylinder then
  9. surface = {"Anything", CN(pospos.p, pos)*CN(0, 0, -(pospos.p - pos).magnitude+0.12)*CA(MR(-90), 0, 0)} --this is if the object is a ball (probably the one you should look @)
  10. else
  11. if pos2.Y > ((siz.Y/2)-0.01) then
  12. surface = {"Top", CA(0, 0, 0)}
  13. elseif pos2.Y < -((siz.Y/2)-0.01) then
  14. surface = {"Bottom", CA(-MP, 0, 0)}
  15. elseif pos2.X > ((siz.X/2)-0.01) then
  16. surface = {"Right", CA(0, 0, MR(-90))}
  17. elseif pos2.X < -((siz.X/2)-0.01) then
  18. surface = {"Left", CA(0, 0, MR(90))}
  19. elseif pos2.Z > ((siz.Z/2)-0.01) then
  20. surface = {"Back", CA(MR(90), 0, 0)}
  21. elseif pos2.Z < -((siz.Z/2)-0.01) then
  22. surface = {"Front", CA(MR(-90), 0, 0)}
  23. end
  24. end
  25. return surface
  26. end
  27.  
  28. --Detached from somewhere of my gun
  29. local Surface = DetectSurface(pos, hit)
  30. local C = CFrame.new(pos) * CFrame.Angles(hit.CFrame:toEulerAnglesXYZ()) * Surface[2] --the angle
  31. local b = Instance.new('Part',Workspace)
  32. b.CFrame = C
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement