1.1.0 โ€ข Published 10 months ago

@rbxts/vector v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Vector

Vector is a highly lightweight utility, served as an addition to Roblox's traditional Vector2 / Vector3 libraries.

Installation

๐Ÿ“ฆ โ€” NPM:

npm i @rbxts/vector

๐Ÿงถ โ€” Yarn:

yarn add @rbxts/vector

๐Ÿ“€ โ€” pnPM:

pnpm add @rbxts/vector

Vector API

Vector.FromVector2XY

function FromVector2XY<T extends Vector>(vector2: Vector2): Vector3 | T;

Create a Vector3 from a Vector2 within the XY plane.

Vector.FromVector2XZ

function FromVector2XZ<T extends Vector>(vector2: Vector2): Vector3 | T;

Create a Vector3 from a Vector2 within the XZ plane.

Vector.GetAngleRad

function GetAngleRad<T extends Vector>(vectorA: Vector2, vectorB: Vector2): number | T;

Compute the angle between two vectors in radians.

Vector.AngleBetweenVectors

function AngleBetweenVectors<T extends Vector>(vectorA: Vector2, vectorB: Vector2): number | T;

Compute the angle between two vectors.

Vector.Round

function Round<T extends Vector>(vectorA: Vector3, amount: number): Vector3 | T;

Round the Vector3 to the nearest number.

Vector.ClampMagnitude

function ClampMagnitude<T extends Vector>(vectorA: Vector, amount: number): number | T;

Clamp the magnitude of a vector so it is only a certain length.

Vector.AngleBetween

function AngleBetween<T extends Vector>(vectorA: Vector, vectorB: Vector): number | T;

Finds the angle in radians between two vectors.

Vector.AngleBetweenSigned

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).

Vector.GetRandomUnitVector

function GetRandomUnitVector<T extends Vector3>(): Vector3 | T;

Return a random unit vector (could be used for equal distribution around a sphere).

Example

// 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);
1.1.0

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago