Advertisement
Oysi

Roblox - Fast getNormal function

Jun 20th, 2014
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1.  
  2. -- Script made by Oysi
  3.  
  4. local pointToObjectSpace = CFrame.new().pointToObjectSpace
  5. local vectorToWorldSpace = CFrame.new().vectorToWorldSpace
  6.  
  7. local v1 = Vector3.new(-1, 0, 0)
  8. local v2 = Vector3.new( 1, 0, 0)
  9. local v3 = Vector3.new(0, -1, 0)
  10. local v4 = Vector3.new(0,  1, 0)
  11. local v5 = Vector3.new(0, 0, -1)
  12. local v6 = Vector3.new(0, 0,  1)
  13.  
  14. function getNormal(part, pos)
  15.     local dif = pointToObjectSpace(part.CFrame, pos) / part.Size
  16.     if     dif.x < -0.499 then return vectorToWorldSpace(part.CFrame, v1)
  17.     elseif dif.x >  0.499 then return vectorToWorldSpace(part.CFrame, v2)
  18.     elseif dif.y < -0.499 then return vectorToWorldSpace(part.CFrame, v3)
  19.     elseif dif.y >  0.499 then return vectorToWorldSpace(part.CFrame, v4)
  20.     elseif dif.z < -0.499 then return vectorToWorldSpace(part.CFrame, v5)
  21.     elseif dif.z >  0.499 then return vectorToWorldSpace(part.CFrame, v6)
  22.     end
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement