Static
DeserializeStatic
addStatic
clampClamp a value between a minimum and a maximum.
The clamped value.
console.log(Vector2.clamp(50, 0, 100)); // => 50
console.log(Vector2.clamp(125, 0, 100)); // => 100
console.log(Vector2.clamp(-50, 0, 100)); // => 0
The value to clamp.
The minimum value.
The maximum value.
Static
distStatic
divDivide one vector from another.
A new vector with one vector divided by the other.
const a = new Vector2(4, 81);
const b = new Vector2(2, 9);
const c = Vector2.div(a, b);
console.log(c); // => (2, 9)
Divide a vector by a scalar value.
A new vector with the vector scaled by the scalar.
const a = new Vector(40, 32);
const c = Vector2.div(a, 8);
console.log(c); // => (5, 4)
The vector to scale.
The scalar.
Static
lerpMap a value between 0 and 1 to between a minimum and maximum value.
The lerped value.
console.log(Vector2.lerp(0.9)); // => 40
console.log(Vector2.lerp(0.9, -30, 30)); // => 24
The value to lerp.
Optional
min: numberThe minimum value to lerp from.
Optional
max: numberThe maximum value to lerp to.
Static
mulMultiply one vector with another.
A new vector with the two vectors multiplied together.
const a = new Vector2(2, 9);
const b = new Vector2(2, 9);
const c = Vector2.mul(a, b);
console.log(c); // => (4, 81)
Scale a vector with a scalar.
A new vector with the vector scaled by the scalar.
const a = new Vector(5, 4);
const c = Vector2.mul(a, 8);
console.log(c); // => (40, 32)
The vector to scale.
The scalar.
Static
negateStatic
normalizeStatic
rotateStatic
rotateStatic
subStatic
unlerpMap a value between a minimum and maximum value to between 0 and 1.
The unlerped value.
console.log(Vector2.unlerp(0)); // => 0.5
console.log(Vector2.unlerp(0, -15, 25)); // => 0.375
The value to unlerp.
Optional
min: numberThe minimum value to unlerp from.
Optional
max: numberThe maximum value to unlerp to.
Static
downStatic
leftStatic
nullStatic
rightStatic
upCreate a 2D Vector from two numbers.
const vector = new Vector2(62, 50);
Optional
x: numberX coordinate of the vector.
Optional
y: numberY coordinate of the vector. Leave out to use the same value as x.
Create a 2D vector from a number tuple.
const vector = new Vector2([ 60, 70 ]);
The X and Y coordinates of the vector.
Create a 2D vector from another 2D vector, cloning it.
const vector = new Vector2(62, 50);
const other = new Vector2(other);
The vector to clone.
Create a 2D vector from an object containing an x and y property.
const vector = new Vector2({
x: 50,
y: 20
});
The object to create from.
The X coordinate of the vector.
The Y coordinate of the vector.
Generated using TypeDoc
Represents a 2D vector in Among Us, i.e. a position or velocity.