Frogger3140

RBX.lua: Checking if a coordinate is in a cuboid

Jun 2nd, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.55 KB | None | 0 0
  1. -- I personally think the variables should be local since you might be using this in a coroutine or in some other weird multitasking scope
  2.  
  3. local corner1 = Vector3.new(-12, -12, -12) -- corner1 of the cuboid
  4. -- corner1 < corner2 in EVERY ordinate or it won't work!
  5. local corner2 = Vector3.new(12, 12, 12) -- corner2 of the cuboid
  6. local checkme = Vector3.new(0, 0, 0) --coordinate we want to check
  7.  
  8. local d = corner2 - corner1
  9. local c = corner2 - checkme
  10.            
  11. if d.x >= c.x and d.y >= c.y and d.z >= c.z then
  12.     --it's true, the object is in the cuboid
  13. end
Advertisement
Add Comment
Please, Sign In to add comment