Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --returns string (of which side it hit), and CFrame Angle
- function DetectSurface(pos, part)
- local surface = nil
- local pospos = part.CFrame
- local pos2 = pospos:pointToObjectSpace(pos)
- local siz = part.Size
- local shaep = part.Shape
- if shaep == Enum.PartType.Ball or shaep == Enum.PartType.Cylinder then
- 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 @)
- else
- if pos2.Y > ((siz.Y/2)-0.01) then
- surface = {"Top", CA(0, 0, 0)}
- elseif pos2.Y < -((siz.Y/2)-0.01) then
- surface = {"Bottom", CA(-MP, 0, 0)}
- elseif pos2.X > ((siz.X/2)-0.01) then
- surface = {"Right", CA(0, 0, MR(-90))}
- elseif pos2.X < -((siz.X/2)-0.01) then
- surface = {"Left", CA(0, 0, MR(90))}
- elseif pos2.Z > ((siz.Z/2)-0.01) then
- surface = {"Back", CA(MR(90), 0, 0)}
- elseif pos2.Z < -((siz.Z/2)-0.01) then
- surface = {"Front", CA(MR(-90), 0, 0)}
- end
- end
- return surface
- end
- --Detached from somewhere of my gun
- local Surface = DetectSurface(pos, hit)
- local C = CFrame.new(pos) * CFrame.Angles(hit.CFrame:toEulerAnglesXYZ()) * Surface[2] --the angle
- local b = Instance.new('Part',Workspace)
- b.CFrame = C
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement