-
Notifications
You must be signed in to change notification settings - Fork 5
Math
The Tmath table provides utility functions for common mathematical operations, vector calculations, interpolation, angle conversion, and random number generation.
Tmathlocal radians = Tmath.DegToRad(degrees)Converts an angle from degrees to radians.
| Name | Type | Description |
|---|---|---|
| degrees | number | Angle in degrees |
numberAngle in radians.
local angle = Tmath.DegToRad(90)local degrees = Tmath.RadToDeg(radians)Converts an angle from radians to degrees.
| Name | Type | Description |
|---|---|---|
| radians | number | Angle in radians |
numberAngle in degrees.
local angle = Tmath.RadToDeg(3.14159)local value = Tmath.Clamp(value, minValue, maxValue)Restricts a value to a specified range.
| Name | Type |
|---|---|
| value | number |
| minValue | number |
| maxValue | number |
numberThe clamped value.
local health = Tmath.Clamp(playerHealth, 0, 100)local value = Tmath.Lerp(a, b, t)Linearly interpolates between two values.
| Name | Type | Description |
|---|---|---|
| a | number | Start value |
| b | number | End value |
| t | number | Interpolation factor |
numberInterpolated value.
local alpha = Tmath.Lerp(0, 100, 0.5)
-- Returns 50local distance = Tmath.Vector2Distance(a, b)Returns the distance between two Vector2 values.
| Name | Type |
|---|---|
| a | Vector2 |
| b | Vector2 |
numberDistance between the vectors.
local distance = Tmath.Vector2DistanceSquared(a, b)Returns the squared distance between two vectors.
This is faster than Vector2Distance() because it avoids a square root operation.
| Name | Type |
|---|---|
| a | Vector2 |
| b | Vector2 |
numberSquared distance.
local dot = Tmath.Vector2Dot(a, b)Returns the dot product of two vectors.
| Name | Type |
|---|---|
| a | Vector2 |
| b | Vector2 |
numberDot product result.
local distance = Tmath.Vector3Distance(a, b)Returns the distance between two Vector3 values.
| Name | Type |
|---|---|
| a | Vector3 |
| b | Vector3 |
numberDistance between the vectors.
local distance = Tmath.Vector3DistanceSquared(a, b)Returns the squared distance between two vectors.
This is faster than Vector3Distance() because it avoids a square root operation.
| Name | Type |
|---|---|
| a | Vector3 |
| b | Vector3 |
numberSquared distance.
local dot = Tmath.Vector3Dot(a, b)Returns the dot product of two vectors.
| Name | Type |
|---|---|
| a | Vector3 |
| b | Vector3 |
numberDot product result.
local cross = Tmath.Vector3Cross(a, b)Calculates the cross product of two vectors.
| Name | Type |
|---|---|
| a | Vector3 |
| b | Vector3 |
Vector3The resulting perpendicular vector.
local right = Tmath.Vector3Cross(forward, up)Generates random integer values.
local value = Tmath.Random(max)Returns a random integer in the range:
0 to max - 1
| Name | Type |
|---|---|
| max | number |
numberA random integer between 0 and max - 1.
local value = Tmath.Random(min, max)Returns a random integer in the range:
min to max
| Name | Type |
|---|---|
| min | number |
| max | number |
numberA random integer between min and max (inclusive).
local dice = Tmath.Random(1, 6)
local enemyIndex = Tmath.Random(10)Generates random floating-point values.
local value = Tmath.RandomF()Returns a random float in the range:
0.0 to 1.0
numberA random floating-point value between 0.0 and 1.0.
local value = Tmath.RandomF(max)Returns a random float in the range:
0.0 to max
| Name | Type |
|---|---|
| max | number |
numberA random floating-point value between 0.0 and max.
local value = Tmath.RandomF(min, max)Returns a random float in the range:
min to max
| Name | Type |
|---|---|
| min | number |
| max | number |
numberA random floating-point value between min and max.
local chance = Tmath.RandomF()
local speed = Tmath.RandomF(0.5, 2.0)
local spread = Tmath.RandomF(5.0)