Math
Abs
x.Abs -> number
Abs(x) -> number
Returns the absolute value of a number.
Returns undefined
if the input is nullish.
Angle
x.Angle -> number
Angle(x) -> number
Returns the angle of a vector in radians.
Returns undefined
if the input is nullish.
AngleDelta
a.AngleDelta(b) -> number
AngleDelta(a, b) -> number
Returns the smallest amount of turn required to get from the angle a
to the angle b
.
May be positive or negative.
Returns 0
if one or both of the inputs is nullish.
Ceiling
x.Ceiling -> number
Ceiling(x) -> number
Returns the smallest integer greater than or equal to a number.
Returns undefined
if the input is nullish.
Clamp
value.Clamp(min, max) -> number
Returns a number clamped between min
and max
.
If min
or max
are nullish, no clamping will be performed on that side.
Returns undefined
if the value
is nullish.
Cos
angle.Cos -> number
Cos(angle) -> number
Returns the cosine of an angle in radians.
Returns undefined
if the input is nullish.
Direction
x.Direction -> vector
Direction(x) -> vector
Returns a unit vector in the direction of x
.
- If
x
is a Number, returns a Vector of anglex
and length 1. - If
x
is a Vector, returns a Vector with the same angle asx
but with length 1. This is sometimes called "normalizing" a vector in maths or other game engines.
Returns undefined
if the input is nullish.
Distance
a.Distance(b) -> number
Distance(a, b) -> number
Returns the distance between two points.
a
and b
must both be Vectors.
Returns 0
if one or both of the inputs is nullish.
Dot
a.Dot(b) -> vector
Dot(a, b) -> vector
Returns the dot product of two Vectors.
Returns 0
if one or both of the inputs is nullish.
Floor
x.Floor -> number
Floor(x) -> number
Returns the largest integer less than or equal to a number.
Returns undefined
if the input is nullish.
Max
a.Max(b) -> value
Max(a, b) -> value
Returns the larger of two values. If both values are Numbers, the larger Number is returned. If both values are Vectors, the longer Vector is returned. If either value is nullish, the other value is returned.
Min
a.Min(b) -> value
Min(a, b) -> value
Returns the smaller of two values. If both values are Numbers, the smaller Number is returned. If both values are Vectors, the shorter Vector is returned. If either value is nullish, the other value is returned.
Mix
alpha.Mix(from, to) -> value
Mix(alpha, from, to) -> value
Returns a value that is a mix between from
and to
.
The mixing is done using linear interpolation.
alpha
controls the amount of blending and should be a value between 0
and 1
,
where 0
is from
and 1
is to
. Defaults to 0
if not provided.
If only one of the inputs is nullish, the other input is returned.
Pi
Pi -> number
Returns the value of PI.
Quantize
x.Quantize(quant) -> number
Quantize(x, quant) -> number
Returns the input x
rounded to the nearest multiple of quant
.
Both x
and quant
can be a Number or a Vector.
If the input is a Vector, quantizes both components of the Vector.
If quant
is also a Vector, quantizes each component of the input using the corresponding component of quant
.
Returns undefined
if either input is nullish.
Examples:
let output1 = Quantize(9.7, 2) // output1 is 10
let output2 = Quantize(@(9.7, 10.2), 2) // output2 is @(10, 10)
let output3 = Quantize(@(9.7, 10.2), @(2, 3)) // output3 is @(10, 9)
Random
this.Random<Id?> -> number
Returns a random floating-point number between 0
(inclusive) and 1
(exclusive).
this
(Entity): Determine's which entity's random number generator to use. If nullish, usesWorld
. This is optional and is only used to help increase stability if a network rollback occurs. Most of the time you should just ignore this parameter.Id
: If provided, specifies which of the entity's random number generators to use. This is optional and is only used to help increase stability if a network rollback occurs. Most of the time you should ignore this parameter . See Random Number Generator Streams.
Examples: Normally, you would just call Random without any arguments.
let x = Random
RandomSeed
this.RandomSeed<Id?>(seed)
Assigns a seed to a random number generator. Random number generators that begin from the same seed will always return the same sequence of numbers.
this
(Entity): Determine's which entity's random number generator to modify. If not provided, defaults toWorld
.Id
: If provided, specifies which of the entity's random number generators to modify. When you generate a random number, you must use the sameId
to get the same sequence of numbers. See Random Number Generator Streams.seed
(Number): The seed to assign to the random number generator. Only the integer part of the number will be used.
RandomVector
this.RandomVector<Id?> -> vector
Returns a Vector with a random angle and length 1.
this
(Entity): Determine's which entity's random number generator to use. If nullish, usesWorld
. This is optional and is only used to help increase stability if a network rollback occurs. Most of the time you should just ignore this parameter.Id
: If provided, specifies which of the entity's random number generators to use. This is optional and is only used to help increase stability if a network rollback occurs. You should not normally need to provide this parameter except in specific cases. See Random Number Generator Streams.
Rotate
x.Rotate(rotate) -> vector
Returns a vector rotated by rotate
radians.
If rotate
is nullish, the input is returned unchanged.
Returns undefined
if the input is nullish.
RotateLeft
x.RotateLeft -> vector
RotateLeft(x) -> vector
Returns a vector rotated 90 degrees to the left.
Returns undefined
if the input is nullish.
RotateRight
x.RotateRight -> vector
RotateRight(x) -> vector
Returns a vector rotated 90 degrees to the right.
Returns undefined
if the input is nullish.
Round
x.Round -> number
Round(x) -> number
Returns the integer nearest to the number.
If the value is halfway between two integers, rounds away from zero.
Returns undefined
if the input is nullish.
Sign
x.Sign -> number
Sign(x) -> number
Returns the sign of a number.
- If the number is positive, returns
1
. - If the number is negative, returns
-1
. - If the number is
0
, returns0
.
Returns undefined
if the input is nullish.
SignedRandom
this.SignedRandom<Id?> -> number
Returns a random floating-point number between -1
(inclusive) and 1
(inclusive).
this
(Entity): Determine's which entity's random number generator to use. If nullish, usesWorld
. Most of the time you should just ignore this parameter.Id
: If provided, specifies which of the entity's random number generators to use. This is optional and is only used to help increase stability if a network rollback occurs. Most of the time you should ignore this parameter. See Random Number Generator Streams.
Examples: Normally, you would just call SignedRandom without any arguments.
let x = SignedRandom
Sin
angle.Sin -> number
Sin(angle) -> number
Returns the sine of an angle in radians.
Returns undefined
if the input is nullish.
Sqrt
x.Sqrt -> number
Sqrt(x) -> number
Returns the square root of a number.
Returns undefined
if the input is nullish.
Tan
angle.Tan -> number
Tan(angle) -> number
Returns the tangent of an angle in radians.
Returns undefined
if the input is nullish.
Towards
a.Towards(b, limit) -> vector
Returns a Vector or Number that moves from a
towards b
by a maximum step of limit
.
In other words, if the distance between a
and b
is less than limit
, returns b
,
otherwise returns a point or value limit
distance away from a
in the direction towards b
.
If both a
and b
are Numbers, performs the calculation in 1-dimension, returning a Number.
If both a
and b
are Vectors, performs the calculation in 2-dimensions, returning a Vector.
If a
is nullish, returns undefined
.
If b
or limit
is nullish, returns a
.
Truncate
x.Truncate(limit) -> numberOrVector
Truncates a Vector or Number to a maximum length.
If x
is a Vector, returns a Vector with a length of at most limit
, but in the same direction.
If x
is a Number, returns a Number with an absolute value of at most limit
, but with the same sign.
If limit
is nullish, returns x
unchanged.
If x
is nullish, returns undefined
.
TwoPi
TwoPi -> number
Returns the value of 2*PI.
WithX
vector.WithX(x) -> vector
Takes a Vector and returns a new Vector with the x
component replaced with a new value.
Returns vector
unchanged if x
is nullish.
Returns undefined
if the vector
is nullish.
WithY
vector.WithY(y) -> vector
Takes a Vector and returns a new Vector with the y
component replaced with a new value.
Returns vector
unchanged if y
is nullish.
Returns undefined
if the vector
is nullish.
X
vector.X -> number
Returns the x
component of a vector.
Returns undefined
if the input is nullish.
Y
vector.Y -> number
Returns the y
component of a vector.
Returns undefined
if the input is nullish.