Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getLeast = function(tab)
- startnum = math.huge
- ind = 0
- if type(tab) == "table" then
- for i, v in pairs(tab) do
- if type(v) == "number" and v < startnum then
- startnum = v
- ind = i
- end
- end
- end
- return startnum ~= math.huge and startnum, ind or startnum == math.huge and "error"
- end
- --
- getSurfaceHit = function(obj, hitter)
- SurfaceTable = {"FrontSurface", "BackSurface", "RightSurface", "LeftSurface", "TopSurface", "BottomSurface"}
- local lengthx = obj.Size.X/2
- local lengthy = obj.Size.Y/2
- local lengthz = obj.Size.Z/2
- local front = (obj.CFrame*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*lengthz))
- local back = (obj.CFrame*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*-lengthz))
- local right = (obj.CFrame*CFrame.Angles(0, math.rad(-90), 0))*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*lengthx)
- local left = (obj.CFrame*CFrame.Angles(0, math.rad(90), 0))*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*lengthx)
- local top = (obj.CFrame*CFrame.Angles(math.rad(90), 0, 0))*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*lengthy)
- local bottom = (obj.CFrame*CFrame.Angles(math.rad(-90), 0, 0))*(obj.CFrame:toObjectSpace(obj.CFrame).lookVector*lengthy)
- --
- local num, index = getLeast({(hitter.Position-front).magnitude, (hitter.Position-back).magnitude, (hitter.Position-right).magnitude, (hitter.Position-left).magnitude, (hitter.Position-top).magnitude, (hitter.Position-bottom).magnitude})
- print(num, index, SurfaceTable[index])
- return SurfaceTable[index]
- end
- --
- for i, v in pairs(script.Parent:GetChildren()) do
- if v:IsA("BasePart") then
- v.Touched:connect(function(hit)
- surface = getSurfaceHit(v, hit)
- print(surface)
- v[surface] = "Studs"
- end)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement