Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. part = workspace.Part
  2. part2 = workspace.Part2
  3.  
  4.  
  5.  
  6.  
  7. function visualize(tbl)
  8.     for i,v in pairs(tbl) do
  9.         local p = Instance.new("Part", workspace)
  10.         p.Anchored = true
  11.         p.CFrame = v
  12.         p.Name = "CFramePart"..i
  13.     end
  14. end
  15.  
  16. function getBiggerRect(p, sizeBigger)
  17.     cf = CFrame.new
  18.     local c1pos = (
  19.         p.CFrame*cf(p.Size.X/2, 0, p.Size.Z/2)*cf(sizeBigger, 0,sizeBigger))   
  20.     local c2pos = (p.CFrame*cf(-p.Size.X/2, 0, -p.Size.Z/2)*cf(-sizeBigger, 0, -sizeBigger))
  21.     local c3pos = (p.CFrame*cf(p.Size.X/2, 0, -p.Size.Z/2)*cf(sizeBigger, 0,- sizeBigger))
  22.     local c4pos = (p.CFrame*cf(-p.Size.X/2, 0, p.Size.Z/2)*cf(-sizeBigger, 0, sizeBigger))
  23.    
  24.     visualize({c1pos, c2pos, c3pos, c4pos})
  25.    
  26.     return c1pos, c2pos, c3pos, c4pos
  27. end
  28.  
  29. function checkIfPartIsNearOtherPart(p, p2, size)
  30.     v2 = Vector2.new
  31.     local c1, c2, c3, c4 = getBiggerRect(p, 5)
  32.    
  33.     local p2cf = p.CFrame:toObjectSpace(p2.CFrame)
  34.    
  35.     local one = c1:toObjectSpace(p2.CFrame)
  36.     local two = c2:toObjectSpace(p2.CFrame)
  37.     local three = c3:toObjectSpace(p2.CFrame)
  38.     local four = c4:toObjectSpace(p2.CFrame)
  39.    
  40.     local condition = (
  41.         (one.X < 0 and one.Z < 0)
  42.         and (two.X > 0 and two.Z > 0)
  43.         and (three.X < 0 and three.Z > 0)
  44.         and (four.X > 0 and four.Z < 0)
  45.     )
  46.     return(condition)
  47.    
  48. end
  49.  
  50. while wait() do
  51.     print(checkIfPartIsNearOtherPart(part, part2, 5))
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement