Vector is a highly lightweight utility, served as an addition to Roblox's traditional Vector2 / Vector3 libraries.
npm i @rbxts/vector
yarn add @rbxts/vector
pnpm add @rbxts/vector
function FromVector2XY<T extends Vector>(vector2: Vector2): Vector3 | T;
Create a Vector3 from a Vector2 within the XY plane.
function FromVector2XZ<T extends Vector>(vector2: Vector2): Vector3 | T;
Create a Vector3 from a Vector2 within the XZ plane.
function GetAngleRad<T extends Vector>(vectorA: Vector2, vectorB: Vector2): number | T;
Compute the angle between two vectors in radians.
function AngleBetweenVectors<T extends Vector>(vectorA: Vector2, vectorB: Vector2): number | T;
Compute the angle between two vectors.
function Round<T extends Vector>(vectorA: Vector3, amount: number): Vector3 | T;
Round the Vector3 to the nearest number.
function ClampMagnitude<T extends Vector>(vectorA: Vector, amount: number): number | T;
Clamp the magnitude of a vector so it is only a certain length.
function AngleBetween<T extends Vector>(vectorA: Vector, vectorB: Vector): number | T;
Finds the angle in radians between two vectors.
function AngleBetweenSigned<T extends Vector>(vectorA: Vector, vectorB: Vector, axisVector: Vector): number | T;
Return a random unit vector (could be used for equal distribution around a sphere).
function GetRandomUnitVector<T extends Vector3>(): Vector3 | T;
Return a random unit vector (could be used for equal distribution around a sphere).
// Services
import { Workspace } from "@rbxts/services";
// Modules
import { GetRandomUnitVector, AngleBetweenSigned } from "@rbxts/vector";
// Functions
const Part = new Instance("Part");
Part.Name = "Part";
Part.Position = GetRandomUnitVector();
Part.Size = GetRandomUnitVector();
Part.Parent = Workspace;
const angleBetweenSigned = AngleBetweenSigned(Part.Position, Part.Size, new Vector3(1, 1, 1));
print(angleBetweenSigned);