ForeverDev

Untitled

Nov 4th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.60 KB | None | 0 0
  1. local Vector3 = {}
  2.  
  3. Vector3.functions = {}
  4.  
  5. Vector3.functions.__add = function(this, other)
  6.     return Vector3.new(this.X + other.X, this.Y + other.Y, this.Z + other.Z)
  7. end
  8.  
  9. Vector3.functions.__sub = function(this, other)
  10.     return Vector3.new(this.X - other.X, this.Y - other.Y, this.Z - other.Z)
  11. end
  12.  
  13. Vector3.setup = function(new)
  14.     return setmetatable(new, Vector3.functions)
  15. end
  16.  
  17. Vector3.new = function(x, y, z)
  18.     return Vector3.setup({
  19.         X = x, Y = y, Z = z,
  20.         magnitude = math.sqrt(x^2 + y^2 + z^2)
  21.     })
  22. end
  23.  
  24. local x = Vector3.new(10, 15, 20) + Vector3.new(5, 5, 5) - Vector3.new(50, 50, 0)
Advertisement
Add Comment
Please, Sign In to add comment