Table of Contents

Struct Vector3I

Namespace
Godot
Assembly
GodotSharp.dll

3-element structure that can be used to represent 3D grid coordinates or sets of integers.

public struct Vector3I : IEquatable<Vector3I>
Implements
Inherited Members

Constructors

Vector3I(int, int, int)

Constructs a new Vector3I with the given components.

public Vector3I(int x, int y, int z)

Parameters

x int

The vector's X component.

y int

The vector's Y component.

z int

The vector's Z component.

Fields

X

The vector's X component. Also accessible by using the index position [0].

public int X

Field Value

int

Y

The vector's Y component. Also accessible by using the index position [1].

public int Y

Field Value

int

Z

The vector's Z component. Also accessible by using the index position [2].

public int Z

Field Value

int

Properties

Back

Back unit vector. Represents the local direction of back, and the global direction of south.

public static Vector3I Back { get; }

Property Value

Vector3I

Equivalent to new Vector3I(0, 0, 1).

Down

Down unit vector.

public static Vector3I Down { get; }

Property Value

Vector3I

Equivalent to new Vector3I(0, -1, 0).

Forward

Forward unit vector. Represents the local direction of forward, and the global direction of north.

public static Vector3I Forward { get; }

Property Value

Vector3I

Equivalent to new Vector3I(0, 0, -1).

this[int]

Access vector components using their index.

public int this[int index] { readonly get; set; }

Parameters

index int

Property Value

int

[0] is equivalent to X, [1] is equivalent to Y, [2] is equivalent to Z.

Exceptions

ArgumentOutOfRangeException

index is not 0, 1 or 2.

Left

Left unit vector. Represents the local direction of left, and the global direction of west.

public static Vector3I Left { get; }

Property Value

Vector3I

Equivalent to new Vector3I(-1, 0, 0).

MaxValue

Max vector, a vector with all components equal to MaxValue. Can be used as an integer equivalent of Inf.

public static Vector3I MaxValue { get; }

Property Value

Vector3I

Equivalent to new Vector3I(int.MaxValue, int.MaxValue, int.MaxValue).

MinValue

Min vector, a vector with all components equal to MinValue. Can be used as a negative integer equivalent of Inf.

public static Vector3I MinValue { get; }

Property Value

Vector3I

Equivalent to new Vector3I(int.MinValue, int.MinValue, int.MinValue).

One

One vector, a vector with all components set to 1.

public static Vector3I One { get; }

Property Value

Vector3I

Equivalent to new Vector3I(1, 1, 1).

Right

Right unit vector. Represents the local direction of right, and the global direction of east.

public static Vector3I Right { get; }

Property Value

Vector3I

Equivalent to new Vector3I(1, 0, 0).

Up

Up unit vector.

public static Vector3I Up { get; }

Property Value

Vector3I

Equivalent to new Vector3I(0, 1, 0).

Zero

Zero vector, a vector with all components set to 0.

public static Vector3I Zero { get; }

Property Value

Vector3I

Equivalent to new Vector3I(0, 0, 0).

Methods

Abs()

Returns a new vector with all components in absolute values (i.e. positive).

public readonly Vector3I Abs()

Returns

Vector3I

A vector with Abs(int) called on each component.

Clamp(Vector3I, Vector3I)

Returns a new vector with all components clamped between the components of min and max using Clamp(int, int, int).

public readonly Vector3I Clamp(Vector3I min, Vector3I max)

Parameters

min Vector3I

The vector with minimum allowed values.

max Vector3I

The vector with maximum allowed values.

Returns

Vector3I

The vector with all components clamped.

Clamp(int, int)

Returns a new vector with all components clamped between the min and max using Clamp(int, int, int).

public readonly Vector3I Clamp(int min, int max)

Parameters

min int

The minimum allowed value.

max int

The maximum allowed value.

Returns

Vector3I

The vector with all components clamped.

Deconstruct(out int, out int, out int)

Helper method for deconstruction into a tuple.

public readonly void Deconstruct(out int x, out int y, out int z)

Parameters

x int
y int
z int

DistanceSquaredTo(Vector3I)

Returns the squared distance between this vector and to. This method runs faster than DistanceTo(Vector3I), so prefer it if you need to compare vectors or need the squared distance for some formula.

public readonly int DistanceSquaredTo(Vector3I to)

Parameters

to Vector3I

The other vector to use.

Returns

int

The squared distance between the two vectors.

DistanceTo(Vector3I)

Returns the distance between this vector and to.

public readonly float DistanceTo(Vector3I to)

Parameters

to Vector3I

The other vector to use.

Returns

float

The distance between the two vectors.

See Also

Equals(Vector3I)

Returns true if the vectors are equal.

public readonly bool Equals(Vector3I other)

Parameters

other Vector3I

The other vector.

Returns

bool

Whether or not the vectors are equal.

Equals(object?)

Returns true if the vector is equal to the given object (obj).

public override readonly bool Equals(object? obj)

Parameters

obj object

The object to compare with.

Returns

bool

Whether or not the vector and the object are equal.

GetHashCode()

Serves as the hash function for Vector3I.

public override readonly int GetHashCode()

Returns

int

A hash code for this vector.

Length()

Returns the length (magnitude) of this vector.

public readonly float Length()

Returns

float

The length of this vector.

See Also

LengthSquared()

Returns the squared length (squared magnitude) of this vector. This method runs faster than Length(), so prefer it if you need to compare vectors or need the squared length for some formula.

public readonly int LengthSquared()

Returns

int

The squared length of this vector.

Max(Vector3I)

Returns the result of the component-wise maximum between this vector and with. Equivalent to new Vector3I(Mathf.Max(X, with.X), Mathf.Max(Y, with.Y), Mathf.Max(Z, with.Z)).

public readonly Vector3I Max(Vector3I with)

Parameters

with Vector3I

The other vector to use.

Returns

Vector3I

The resulting maximum vector.

Max(int)

Returns the result of the component-wise maximum between this vector and with. Equivalent to new Vector3I(Mathf.Max(X, with), Mathf.Max(Y, with), Mathf.Max(Z, with)).

public readonly Vector3I Max(int with)

Parameters

with int

The other value to use.

Returns

Vector3I

The resulting maximum vector.

MaxAxisIndex()

Returns the axis of the vector's highest value. See Vector3I.Axis. If all components are equal, this method returns X.

public readonly Vector3I.Axis MaxAxisIndex()

Returns

Vector3I.Axis

The index of the highest axis.

Min(Vector3I)

Returns the result of the component-wise minimum between this vector and with. Equivalent to new Vector3I(Mathf.Min(X, with.X), Mathf.Min(Y, with.Y), Mathf.Min(Z, with.Z)).

public readonly Vector3I Min(Vector3I with)

Parameters

with Vector3I

The other vector to use.

Returns

Vector3I

The resulting minimum vector.

Min(int)

Returns the result of the component-wise minimum between this vector and with. Equivalent to new Vector3I(Mathf.Min(X, with), Mathf.Min(Y, with), Mathf.Min(Z, with)).

public readonly Vector3I Min(int with)

Parameters

with int

The other value to use.

Returns

Vector3I

The resulting minimum vector.

MinAxisIndex()

Returns the axis of the vector's lowest value. See Vector3I.Axis. If all components are equal, this method returns Z.

public readonly Vector3I.Axis MinAxisIndex()

Returns

Vector3I.Axis

The index of the lowest axis.

Sign()

Returns a vector with each component set to one or negative one, depending on the signs of this vector's components, or zero if the component is zero, by calling Sign(int) on each component.

public readonly Vector3I Sign()

Returns

Vector3I

A vector with all components as either 1, -1, or 0.

Snapped(Vector3I)

Returns a new vector with each component snapped to the closest multiple of the corresponding component in step.

public readonly Vector3I Snapped(Vector3I step)

Parameters

step Vector3I

A vector value representing the step size to snap to.

Returns

Vector3I

The snapped vector.

Snapped(int)

Returns a new vector with each component snapped to the closest multiple of step.

public readonly Vector3I Snapped(int step)

Parameters

step int

The step size to snap to.

Returns

Vector3I

The snapped vector.

ToString()

Converts this Vector3I to a string.

public override readonly string ToString()

Returns

string

A string representation of this vector.

ToString(string?)

Converts this Vector3I to a string with the given format.

public readonly string ToString(string? format)

Parameters

format string

Returns

string

A string representation of this vector.

Operators

operator +(Vector3I, Vector3I)

Adds each component of the Vector3I with the components of the given Vector3I.

public static Vector3I operator +(Vector3I left, Vector3I right)

Parameters

left Vector3I

The left vector.

right Vector3I

The right vector.

Returns

Vector3I

The added vector.

operator /(Vector3I, Vector3I)

Divides each component of the Vector3I by the components of the given Vector3I.

public static Vector3I operator /(Vector3I vec, Vector3I divisorv)

Parameters

vec Vector3I

The dividend vector.

divisorv Vector3I

The divisor vector.

Returns

Vector3I

The divided vector.

operator /(Vector3I, int)

Divides each component of the Vector3I by the given int.

public static Vector3I operator /(Vector3I vec, int divisor)

Parameters

vec Vector3I

The dividend vector.

divisor int

The divisor value.

Returns

Vector3I

The divided vector.

operator ==(Vector3I, Vector3I)

Returns true if the vectors are equal.

public static bool operator ==(Vector3I left, Vector3I right)

Parameters

left Vector3I

The left vector.

right Vector3I

The right vector.

Returns

bool

Whether or not the vectors are equal.

explicit operator Vector3I(Vector3)

Converts a Vector3 to a Vector3I by truncating components' fractional parts (rounding towards zero). For a different behavior consider passing the result of Ceil(), Floor() or Round() to this conversion operator instead.

public static explicit operator Vector3I(Vector3 value)

Parameters

value Vector3

The vector to convert.

Returns

Vector3I

operator >(Vector3I, Vector3I)

Compares two Vector3I vectors by first checking if the X value of the left vector is greater than the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, and then with the Z values. This operator is useful for sorting vectors.

public static bool operator >(Vector3I left, Vector3I right)

Parameters

left Vector3I

The left vector.

right Vector3I

The right vector.

Returns

bool

Whether or not the left is greater than the right.

operator >=(Vector3I, Vector3I)

Compares two Vector3I vectors by first checking if the X value of the left vector is greater than or equal to the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, and then with the Z values. This operator is useful for sorting vectors.

public static bool operator >=(Vector3I left, Vector3I right)

Parameters

left Vector3I

The left vector.

right Vector3I

The right vector.

Returns

bool

Whether or not the left is greater than or equal to the right.

implicit operator Vector3(Vector3I)

Converts this Vector3I to a Vector3.

public static implicit operator Vector3(Vector3I value)

Parameters

value Vector3I

The vector to convert.

Returns

Vector3

operator !=(Vector3I, Vector3I)

Returns true if the vectors are not equal.

public static bool operator !=(Vector3I left, Vector3I right)

Parameters

left Vector3I

The left vector.

right Vector3I

The right vector.

Returns

bool

Whether or not the vectors are not equal.

operator <(Vector3I, Vector3I)

Compares two Vector3I vectors by first checking if the X value of the left vector is less than the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, and then with the Z values. This operator is useful for sorting vectors.

public static bool operator <(Vector3I left, Vector3I right)

Parameters

left Vector3I

The left vector.

right Vector3I

The right vector.

Returns

bool

Whether or not the left is less than the right.

operator <=(Vector3I, Vector3I)

Compares two Vector3I vectors by first checking if the X value of the left vector is less than or equal to the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors, and then with the Z values. This operator is useful for sorting vectors.

public static bool operator <=(Vector3I left, Vector3I right)

Parameters

left Vector3I

The left vector.

right Vector3I

The right vector.

Returns

bool

Whether or not the left is less than or equal to the right.

operator %(Vector3I, Vector3I)

Gets the remainder of each component of the Vector3I with the components of the given Vector3I. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using PosMod(int, int) instead if you want to handle negative numbers.

public static Vector3I operator %(Vector3I vec, Vector3I divisorv)

Parameters

vec Vector3I

The dividend vector.

divisorv Vector3I

The divisor vector.

Returns

Vector3I

The remainder vector.

Examples

GD.Print(new Vector3I(10, -20, 30) % new Vector3I(7, 8, 9)); // Prints "(3, -4, 3)"

operator %(Vector3I, int)

Gets the remainder of each component of the Vector3I with the components of the given int. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using PosMod(int, int) instead if you want to handle negative numbers.

public static Vector3I operator %(Vector3I vec, int divisor)

Parameters

vec Vector3I

The dividend vector.

divisor int

The divisor value.

Returns

Vector3I

The remainder vector.

Examples

GD.Print(new Vector3I(10, -20, 30) % 7); // Prints "(3, -6, 2)"

operator *(Vector3I, Vector3I)

Multiplies each component of the Vector3I by the components of the given Vector3I.

public static Vector3I operator *(Vector3I left, Vector3I right)

Parameters

left Vector3I

The left vector.

right Vector3I

The right vector.

Returns

Vector3I

The multiplied vector.

operator *(Vector3I, int)

Multiplies each component of the Vector3I by the given int.

public static Vector3I operator *(Vector3I vec, int scale)

Parameters

vec Vector3I

The vector to multiply.

scale int

The scale to multiply by.

Returns

Vector3I

The multiplied vector.

operator *(int, Vector3I)

Multiplies each component of the Vector3I by the given int.

public static Vector3I operator *(int scale, Vector3I vec)

Parameters

scale int

The scale to multiply by.

vec Vector3I

The vector to multiply.

Returns

Vector3I

The multiplied vector.

operator -(Vector3I, Vector3I)

Subtracts each component of the Vector3I by the components of the given Vector3I.

public static Vector3I operator -(Vector3I left, Vector3I right)

Parameters

left Vector3I

The left vector.

right Vector3I

The right vector.

Returns

Vector3I

The subtracted vector.

operator -(Vector3I)

Returns the negative value of the Vector3I. This is the same as writing new Vector3I(-v.X, -v.Y, -v.Z). This operation flips the direction of the vector while keeping the same magnitude.

public static Vector3I operator -(Vector3I vec)

Parameters

vec Vector3I

The vector to negate/flip.

Returns

Vector3I

The negated/flipped vector.