API reference / @jsprismarine/math / Vector3
Class: Vector3
Defined in: Vector3.ts:6
3D Vector.
Extends
Extended by
Constructors
Constructor
new Vector3(
x,y,z):Vector3
Defined in: Vector3.ts:22
Create a new Vector3 instance.
Parameters
x
number
The X coordinate.
y
number
The Y coordinate.
z
number
The Z coordinate.
Returns
Vector3
Example
const vector = new Vector3(10, 20, 30);Overrides
Properties
ZERO
readonlystaticZERO:Vector3
Defined in: Vector3.ts:10
Returns a Vector3 with 0 on all axis.
Overrides
Methods
distanceSquaredTo()
distanceSquaredTo(
vector):number
Defined in: Vector3.ts:150
The squared distance to another vector.
Squared, and offered first, because almost every caller compares a distance against another distance - and a comparison of squares gives the same answer without the square root. Prefer this to Vector3.distanceTo wherever the number itself is not shown to anyone.
Parameters
vector
Vector3
The vector to measure to.
Returns
number
The squared distance.
Example
if (a.distanceSquaredTo(b) <= range * range) {
// within range, with no square root taken
}distanceTo()
distanceTo(
vector):number
Defined in: Vector3.ts:166
The distance to another vector.
Parameters
vector
Vector3
The vector to measure to.
Returns
number
The distance.
Example
const meters = player.getPosition().distanceTo(target.getPosition());equals()
equals(
vector):boolean
Defined in: Vector3.ts:130
Compare an instance of Vector3 with another.
The parameter type matches the base declaration because ahead-of-time compilation only lowers overrides with identical signatures; a plain Vector2 is never equal to a Vector3.
Parameters
vector
The vector to compare to.
Returns
boolean
true if they're equal otherwise false.
Overrides
floor()
floor():
this
Defined in: Vector3.ts:109
Returns a new Vector3 with each component rounded down to the nearest integer.
Returns
this
A new vector with rounded down components.
Overrides
getX()
getX():
number
Defined in: Vector2.ts:67
Get the x coordinate.
Returns
number
The x coordinate's value.
Inherited from
getY()
getY():
number
Defined in: Vector3.ts:101
Get the y coordinate.
Returns
number
The y coordinate's value.
getZ()
getZ():
number
Defined in: Vector2.ts:75
Get the z coordinate.
Returns
number
The z coordinate's value.
Inherited from
toString()
toString():
string
Defined in: Vector3.ts:30
Returns
string
Overrides
trunc()
trunc():
this
Defined in: Vector3.ts:117
Returns a new Vector3 with each component truncated to the nearest integer.
Returns
this
A new vector with truncated axis.
Overrides
withX()
withX(
x):this
Defined in: Vector3.ts:67
Returns a copy with a different X coordinate.
Parameters
x
number
The X coordinate.
Returns
this
A new vector; this one is left alone.
Example
const moved = vector.withX(10);Overrides
withY()
withY(
y):this
Defined in: Vector3.ts:80
Returns a copy with a different Y coordinate.
Parameters
y
number
The Y coordinate.
Returns
this
A new vector; this one is left alone.
Example
const moved = vector.withY(10);withZ()
withZ(
z):this
Defined in: Vector3.ts:93
Returns a copy with a different Z coordinate.
Parameters
z
number
The Z coordinate.
Returns
this
A new vector; this one is left alone.
Example
const moved = vector.withZ(10);Overrides
fromObject()
staticfromObject(obj):Vector3
Defined in: Vector3.ts:39
Creates a new Vector3 instance from an object with x, y, and z properties.
Parameters
obj
The object containing x, y, and z properties.
x
number
y
number
z
number
Returns
Vector3
A new Vector3 instance.