Advertisement
qwertyMAN_rus

Roblox Math library

May 2nd, 2022 (edited)
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. local Math = {}
  2.  
  3. function Math.convert(value)
  4.     value = (value + 1)*math.pi
  5.     return (math.cos(value)/2 + 0.5)
  6. end
  7. function Math.Round(number, i)
  8.     number = number or 0
  9.     i = i or 0
  10.     local n = 10^i
  11.     return math.round(number*n)/n
  12. end
  13. function Math.Lerp(startValue, finishValue, n)
  14.     return startValue + (finishValue - startValue) * n
  15. end
  16. function Math.ConvertVector2ToVector3(vector, axis)
  17.     local x = 0
  18.     local y = 0
  19.     local z = 0
  20.     if axis == Enum.Axis.X then
  21.         x = 0
  22.         y = vector.Y
  23.         z = vector.X
  24.     elseif axis == Enum.Axis.Z then
  25.         x = vector.X
  26.         y = vector.Y
  27.         z = 0
  28.     else
  29.         x = vector.X
  30.         y = 0
  31.         z = vector.Y
  32.     end
  33.     return Vector3.new(x, y, z)
  34. end
  35. function Math.RandomVector2(min, max)
  36.     local x = math.random(min, max)
  37.     local y = math.random(min, max)
  38.     return Vector2.new(x, y)
  39. end
  40. function Math.RandomVector3(min, max)
  41.     local x = math.random(min, max)
  42.     local y = math.random(min, max)
  43.     local z = math.random(min, max)
  44.     return Vector3.new(x, y, z)
  45. end
  46. function Math.ConvertOrientationToVector2(angle)
  47.     return Vector2.new(math.cos(angle), math.sin(angle))
  48. end
  49. function Math.ConvertOrientationToVector3(vX, vY, vZ)
  50.     local x = vY.+ 0     + vZ.X
  51.     local y = 0     + vX.+ vZ.Y
  52.     local z = vX.+ vY.+ 0
  53.     return Vector3.new(x, y, z).Unit
  54. end
  55. function Math.RandomDirection2()
  56.     local direction = math.random()*math.pi*2
  57.     return Math.ConvertOrientationToVector2(direction)
  58. end
  59. function Math.RandomDirection3()
  60.     local vX = Math.RandomDirection2()
  61.     local vY = Math.RandomDirection2()
  62.     local vZ = Math.RandomDirection2()
  63.     return Math.ConvertOrientationToVector3(vX, vY, vZ)
  64. end
  65.  
  66. return Math
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement