Skip to main content

Vector3

class Vector3

Vector3 is a Vector with 3 positions, respectively, X, Y and Z, that is, a vector in 3d dimension space. They are used to store positions, directions, etc.


public class Vector3

β€” Constructors (9) β€”

ConstructorDescription
Vector3()Creates a new Vector3 with all values setted as 0.
Vector3(float a)Creates a new Vector3 with the three axes [X, Y, Z] defined with the value of the argument "a".
Vector3(int a)Creates a new Vector3 with the three axes [X, Y, Z] defined with the value of the argument "a".
Vector3(float x, float y, float z)Creates a new Vector3 with X, Y and Z setted as "x" , "y" and "z" arguments respectively.
Vector3(int x, int y, int z)Creates a new Vector3 with X, Y and Z setted as "x" , "y" and "z" arguments respectively.
Vector3(float x, float y, int z)Creates a new Vector3 with X, Y and Z setted as "x" , "y" and "z" arguments respectively.
Vector3(int x, float y, int z)Creates a new Vector3 with X, Y and Z setted as "x" , "y" and "z" arguments respectively.
Vector3(int x, float y, float z)Creates a new Vector3 with X, Y and Z setted as "x" , "y" and "z" arguments respectively.
Vector3(int x, int y, float z)Creates a new Vector3 with X, Y and Z setted as "x" , "y" and "z" arguments respectively.

β€” Methods (102) β€”

NameDescription
float getX()Return the current X value inside of this vector.
float getY()Return the current Y value inside of this vector.
float getZ()Return the current Z value inside of this vector.
Vector2 getXY()Return the current X and Y value inside of this vector.
Vector2 getXZ()Return the current X and Z value inside of this vector.
Vector2 getYZ()Return the current Y and Z value inside of this vector.
Vector2 getYX()Return the current Y and X value inside of this vector.
Vector2 getZX()Return the current Z and X value inside of this vector.
Vector2 getZY()Return the current Z and Y value inside of this vector.
void setX(float value)Sets the current X value inside of this vector with a new value.
void setY(float value)Sets the current Y value inside of this vector with a new value.
void setZ(float value)Sets the current Z value inside of this vector with a new value.
void set(Vector3 value)Sets the current value within this vector with a new vector of the argument.
void set(float a)Sets the current value within this vector to a new value.
void set(float x, float y, float z)Sets the current x, y and z value within this vector to a new value.
void SetXY(Vector2 v)Sets the current X and Y value inside of this vector with a new value.
void SetXZ(Vector2 v)Sets the current X and Z value inside of this vector with a new value.
void SetYZ(Vector2 v)Sets the current Y and Z value inside of this vector with a new value.
void SetYX(Vector2 v)Sets the current Y and X value inside of this vector with a new value.
void SetZX(Vector2 v)Sets the current Z and X value inside of this vector with a new value.
void SetZY(Vector2 v)Sets the current Z and Y value inside of this vector with a new value.
Vector3 mul(Vector3 value)Multiplies the current vector values with the input vector values and return a new instance with these multiplied values.
Vector3 mul(float x, float y, [float z])Multiplies the current vector values with the input X , Y and Z values and return a new instance with these multiplied values.
Vector3 mul(float a)Multiplies the current vector values with the input "a" and return a new instance of these multiplied values.
void mulX(float value)Multiplies the value of the argument to the X axis of the vector.
void mulY(float value)Multiplies the value of the argument to the Y axis of the vector.
void mulZ(float value)Multiplies the value of the argument to the Z axis of the vector.
void mulLocal(Vector3 value)Multiply the current values of the vector by the values of the input vector and apply to the vector itself.
void mulLocal(Vector2 value)Multiply the current values of the vector by the values of the input vector and apply to the vector itself.
void mulLocal(float a)Multiply the current values of the vector by the input "a" and apply to the vector itself.
void mulLocal(float x, float y, float z)Multiply the current values of the vector by the input values X , Y and Z and apply to the vector itself.
Vector3 div(Vector3 value)Divides the current vector values with the input vector values and return a new instance with these divided values.
Vector3 div(float x, float y, [float z])Divides the current vector values with the input X , Y and Z values and return a new instance with these divided values.
Vector3 div(float a)Divides the current vector values with the input "a" and return a new instance with these divided values.
void divX(float value)Divides the value of the argument to the X axis of the vector.
void divY(float value)Divides the value of the argument to the Y axis of the vector.
void divZ(float value)Divides the value of the argument to the Z axis of the vector.
void divLocal(Vector3 value)Divide current vector values with input vector values and apply to vector itself.
void divLocal(Vector2 value)Divide current vector values with input vector values and apply to vector itself.
void divLocal(float a)Divide the current values of the vector with the input "a" and apply it to the vector itself.
void divLocal(float x, float y, float z)Divide the current values of the vector with the input values X, Y and Z and apply to the vector itself.
Vector3 sum(Vector3 value)Increments the current vector values with the input vector values and return a new instance with these incremented values.
Vector3 sum(float x, float y, float z)Increments the current vector values with the input X , Y and Z values and return a new instance with these incremented values.
Vector3 sum(float a)Increments the current vector values with the input "a" and return a new instance with these incremented values.
void sumX(float value)Adds the value of the argument to the X axis of the vector.
void sumY(float value)Adds the value of the argument to the Y axis of the vector.
void sumZ(float value)Adds the value of the argument to the Z axis of the vector.
void sumLocal(Vector3 value)Increments the current values of the vector with the values of the input vector and applies to the vector itself.
void sumLocal(Vector2 value)Increments the current values of the vector with the values of the input vector and applies to the vector itself.
void sumLocal(float a)Increments the current values of the vector with the input "a" and apply it to the vector itself.
void sumLocal(float x, float y, float z)Increments the current values of the vector with the input values X , Y and Z and applies it to the vector itself.
Vector3 sub(Vector3 value)Subtracts the current vector values with the input vector values and return a new instance with these subtracted values.
Vector3 sub(float x, float y, float z)Subtracts the current vector values with the input X , Y and Z and return a new instance with these subtracted values.
Vector3 sub(float a)Subtracts the curtent vector values with the input "a" and return a new instance with these subtracted values.
void subX(float value)Subtracts the value of the argument from the X axis of the vector.
void subY(float value)Subtracts the value of the argument from the Y axis of the vector.
void subZ(float value)subtracts the value of the argument from the Z axis of the vector.
void subLocal(Vector3 value)Subtracts the current vector values from the input vector values and applies it to the vector itself.
void subLocal(Vector2 value)Subtracts the current vector values from the input vector values and applies it to the vector itself.
void subLocal(float a)Subtracts the current values from the vector with the input "a" and applies it to the vector itself.
void subLocal(float x, float y, float z)Subtracts the current values of the vector with the input X , Y and Z and applies it to the vector itself.
boolean equals(Vector3 value)Compares the first vector with the one in the argument, returns true if the values match.
boolean equals(float a)Compares first vector with argument value, returns true if values match.
boolean equals(float x, float y, float z)Compares the vector with the value of the arguments respectively X, Y and Z, returns true if the values match.
float length()Returns the length of the vector with the square root.
float sqrLength()Returns the length of the vector without square root.
float distance(Vector3 value)Returns the distance between two vectors with the square root.
float sqrDistance(Vector3 value)Returns the distance between two vectors without the square root.
Vector3 copy()Returns the perfect copy of a vector.
String toString()Returns vector values to a String.
String toString(int decimals)Defines the number of decimal places that the axes will have when creating the string.
Vector3 zero()Returns a new vector with its axes at 0.
Vector3 one()Returns a new vector with its axes at 1.
Vector3 normalize()Makes the vector have a magnitude of 1, the vector keeps the same direction but its length is 1.0, if the vector is too small to normalize, it is set to zero.
void normalizeLocal()Makes the vector have magnitude 1, the vector keeps the same direction, but its length is 1.0, the difference to "normalize" is that this method applies the modification to the vector itself, if the vector is too small to normalize , is set to zero.
Vector3 sqrNormalize()Makes the vector have a magnitude of 1 squared, the vector keeps the same direction but its length is 1.0, if the vector is too small to normalize it is set to zero.
void sqrNormalizeLocal()Makes the vector have magnitude 1 squared, the vector keeps the same direction but its length is 1.0, the difference to "normalize" is that this method applies the modification to the vector itself, if the vector is too small to normalize, is set to zero.
float dot(Vector3 value)Calculates the dot product of this vector and the vector passed in the argument and returns the value.
float dot(float a)Calculates the dot product of this vector and the value passed in the argument and returns the value.
float dot(float x, float y, float z)Calculates the dot product of this vector and the values passed, x, y, and z in the argument and returns the value
Vector3 cross(Vector3 value)Cross Product of two vectors. The cross product of two vectors results in a third vector which is perpendicular to the two input vectors. The result's magnitude is equal to the magnitudes of the two inputs multiplied together and then multiplied by the sine of the angle between the inputs.
Vector3 cross(float x, float y, float z)Cross product of two vectors, respectively x, y and z, the cross product of two vectors results in a third vector that is perpendicular to the two input vectors. The magnitude of the result is equal to the magnitudes of the two inputs multiplied together and then multiplied by the sine of the angle between the inputs.
void lerp(Vector3 value, float speed)Smoothes that vector into another based on a speed.
void lerp(float a, float speed)Smoothes that vector into another based on a speed.
void lerp(float x, float y, float z, float speed)Smoothes one vector into another, respectively x, y and z based on a velocity.
void lerpInSeconds(Vector3 value, float speed)Smoothes one vector into another, based on a speed multiplied by "Math.bySecond(1)".
void lerpInSeconds(float a, float speed)Smoothes one vector into another, based on a speed multiplied by "Math.bySecond(1)".
void lerpInSeconds(float x, float y, float z float speed)Smoothes one vector into another, respectively x, y and z based on a velocity multiplied by "Math.bySecond(1)".
void blend(Vector3 value, float blend)Mix the vector with another.
void blend(float a, float blend)Mix the vector with another, given a 0-1 percentage.
void blend(float x, float y, float z)Mixes the vector with another, respectively, x , y and z, given a 0-1 percentage.
float magnitude()Returns the length of this vector.
float sqrMagnitude()Returns the squared length of this vector.
Vector3 smoothDamp(Vector3 a, Vector3 b, Vector3 velocity, float smoothTime, float maxSpeed, float deltaTime)Transforms one vector into another smoothly taking into account the passage of time correctly, to prevent framerate drops from causing a "shake" in the smoothing.
Vector3 smoothDamp(Vector3 a, Vector3 b, Vector3 velocity, float smoothTime, float maxSpeed, float deltaTime, Vector3 out)Transforms one vector into another smoothly taking into account the passage of time correctly, to prevent framerate drops from causing a "shake" in the smoothing.
Vector3 triangleNormal(Vector3 a, Vector3 b, Vector3 c)Calculates the normal of a face given its 3 vertices.
Vector3 triangleNormal(Vector3 a, Vector3 b, Vector3 c, Vector3 out)Calculates the normal of a face given its 3 vertices.
Vector3 reflect(Vector3 dir, Vector3 normal)Calculates the reflection vector given 2 other vectors.
Vector3 reflect(Vector3 dir, Vector3 normal, Vector3 out)Calculates the reflection vector given 2 other vectors and applies it to the "out" argument vector itself.
float angle(Vector3 a, Vector3 b)Calculates the angle in degrees between 2 vectors.
Vector3 rotateAroundPivot(Vector3 vector, float angle)Rotates the vector the amount of degrees determined by the "angle" argument around the 0, 0, 0 coordinates.
Vector3 rotateAroundPivot(Vector3 vector, Vector3 pivot, float angle)Rotates the vector the amount of degrees determined by the "angle" argument around the "pivot" coordinates.

β€” Static Methods (9) β€”

NameDescription
Vector3 Min(Vector3 value1, Vector3 value2)Returns a vector formed by the smallest values of two vectors.
Vector3 Max(Vector3 value1, Vector3 value2)Returns a vector formed by the largest values of two vectors.
Vector3 Negate(Vector3 value)Returns the negative value of the vector.
Vector3 up()Returns a new Vector3 with its values being [0, 1, 0].
Vector3 down()Returns a new Vector3 with its values being [0, -1, 0].
Vector3 back()Returns a new Vector3 with its values being [0, 0, -1].
Vector3 forward()Returns a new Vector3 with its values being [0, 0, 1].
Vector3 left()Returns a new Vector3 with its values being [-1, 0, 0].
Vector3 right()Returns a new Vector3 with its values being [1, 0, 0].

β€” Operators (10) β€”

+ Sum 2 vectors and return a new with the result.

Vector3 a = new Vector3(1, 0, 0);  
Vector3 b = new Vector3(1, 0, 1);

a + b;

// a = {2, 0, 1}

- Decreases 2 vectors and returns a new with the result.

Vector3 a = new Vector3(6, 5, 4);  
Vector3 b = new Vector3(6, 2, 3);

a - b;

// a = {0, 3, 1}

* Multiplies 2 vectors and returns a new with the result.

Vector3 a = new Vector3(5, 2, 4);  
Vector3 b = new Vector3(5, 2, 4);

a * b;

// a = {25, 4, 16}

/ Divide 2 vectors and returns a new with the result.

Vector3 a = new Vector3(1, 2, 3);  
Vector3 b = new Vector3(1, 2, 3);

a / b;

// a = {1, 1, 1}

+= Sum 2 vectors and apply the result to the vector itself.

Vector3 a = new Vector3(5, 5, 5);  
Vector3 b = new Vector3(2, 3, 1);

a += b;

// a = {7, 8, 6}

-= Decreases 2 vectors and apply the result to the vector itself.

Vector3 a = new Vector3(5, 5, 5);  
Vector3 b = new Vector3(4, 5, 1);

a -= b;

// a = {1, 0, 1}

/= Divide 2 vectors and apply the result to the vector itself.

Vector3 a = new Vector3(10, 0, 0);  
Vector3 b = new Vector3(5, 0, 0);

a /= b;

// a = {2, 0, 0}

*= Multiplies 2 vectors and apply the result to the vector itself.

Vector3 a = new Vector3(2, 2, 2);
Vector3 b = new Vector3(4, 3, 2);

a *= b;

// a = {8, 6, 4}

++ Sum 1 to the vector.

Vector3 a = new Vector3(5, 0, 0);

a++;

// a = {6, 0, 0}

-- Decreases 1 from the vector.

Vector3 a = new Vector3(5, 0, 0);  

a--;

// a = {4, 0, 0}

β€” Comparators (5) β€”

>= Compares whether the length of the vector is greater than or equal to the other.

Vector3 a = new Vector3(10,0,0);  

if(a >= 10){

// TRUE because the length of the vector "a" is 10 or greater

}

<= Compares whether the length of the vector is less than or equal to the other.

Vector3 a = new Vector3(10,0,0);  

if(a <= 15){

// TRUE because the length is less than "15"

}

> Compares if the length of the vector is greater than the other.

Vector3 a = new Vector3(10,0,0);  

if(a > 10){

// FALSE because the length of the vector "a" is 10 not greater

}

< Compares if the length of the vector is greater than the other.

Vector3 a = new Vector3(10,0,0);  

if(a < 10){

// FALSE because the length of vector "a" is not less than 10

}

== Compares if the 3 axes of Vector3 are equal.

Vector3 a = new Vector3(10, 10, 10);
Vector3 b = new Vector3(10, 10, 10);

if(a == b){

// TRUE because the length of vector "a" is equal to that of vector "b"

}