Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- part = workspace.Part
- part2 = workspace.Part2
- function visualize(tbl)
- for i,v in pairs(tbl) do
- local p = Instance.new("Part", workspace)
- p.Anchored = true
- p.CFrame = v
- p.Name = "CFramePart"..i
- end
- end
- function getBiggerRect(p, sizeBigger)
- cf = CFrame.new
- local c1pos = (
- p.CFrame*cf(p.Size.X/2, 0, p.Size.Z/2)*cf(sizeBigger, 0,sizeBigger))
- local c2pos = (p.CFrame*cf(-p.Size.X/2, 0, -p.Size.Z/2)*cf(-sizeBigger, 0, -sizeBigger))
- local c3pos = (p.CFrame*cf(p.Size.X/2, 0, -p.Size.Z/2)*cf(sizeBigger, 0,- sizeBigger))
- local c4pos = (p.CFrame*cf(-p.Size.X/2, 0, p.Size.Z/2)*cf(-sizeBigger, 0, sizeBigger))
- visualize({c1pos, c2pos, c3pos, c4pos})
- return c1pos, c2pos, c3pos, c4pos
- end
- function checkIfPartIsNearOtherPart(p, p2, size)
- v2 = Vector2.new
- local c1, c2, c3, c4 = getBiggerRect(p, 5)
- local p2cf = p.CFrame:toObjectSpace(p2.CFrame)
- local one = c1:toObjectSpace(p2.CFrame)
- local two = c2:toObjectSpace(p2.CFrame)
- local three = c3:toObjectSpace(p2.CFrame)
- local four = c4:toObjectSpace(p2.CFrame)
- local condition = (
- (one.X < 0 and one.Z < 0)
- and (two.X > 0 and two.Z > 0)
- and (three.X < 0 and three.Z > 0)
- and (four.X > 0 and four.Z < 0)
- )
- return(condition)
- end
- while wait() do
- print(checkIfPartIsNearOtherPart(part, part2, 5))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement