# `unreal.Vector`¶

class unreal.Vector(x=0.0, y=0.0, z=0.0)

A point or direction FVector in 3d space. note: The full C++ class is located here: EngineSourceRuntimeCorePublicMathVector.h

C++ Source:

• Module: CoreUObject

• File: NoExportTypes.h

Editor Properties: (see get_editor_property/set_editor_property)

• `x` (float): [Read-Write] X

• `y` (float): [Read-Write] Y

• `z` (float): [Read-Write] Z

BACKWARD = None

3D vector Unreal backward direction constant (-1,0,0)

Type

(Vector)

DOWN = None

3D vector Unreal down direction constant (0,0,-1)

Type

(Vector)

FORWARD = None

3D vector Unreal forward direction constant (1,0,0)

Type

(Vector)

LEFT = None

3D vector Unreal left direction constant (0,-1,0)

Type

(Vector)

ONE = None

3D vector one constant (1,1,1)

Type

(Vector)

RIGHT = None

3D vector Unreal right direction constant (0,1,0)

Type

(Vector)

UP = None

3D vector Unreal up direction constant (0,0,1)

Type

(Vector)

ZERO = None

3D vector zero constant (0,0,0)

Type

(Vector)

• `Vector` Vector addition

__eq__(other)

• `Vector` Returns true if vector A is equal to vector B (A == B)

• `Vector` Vector addition

__imul__(other)

• `Vector` Element-wise Vector multiplication (Result = {A.x*B.x, A.y*B.y, A.z*B.z})

• `float` Scales Vector A by B

__isub__(other)

• `Vector` Vector subtraction

__mul__(other)

• `Vector` Element-wise Vector multiplication (Result = {A.x*B.x, A.y*B.y, A.z*B.z})

• `float` Scales Vector A by B

__ne__(other)

• `Vector` Returns true if vector A is not equal to vector B (A != B)

__neg__()

Negate a vector.

__or__(other)

__sub__(other)

• `Vector` Vector subtraction

__truediv__(other)

• `Vector` Element-wise Vector division (Result = {A.x/B.x, A.y/B.y, A.z/B.z})

• `float` Vector divide by a float

__xor__(other)

Parameters

b (Vector) –

Returns

Return type

Vector

Add a vector to this and clamp the result to an axis aligned cube centered at the origin.

Parameters

• radius (float) – Half size of the cube.

Adds a float to each component of a vector

Parameters

b (float) –

Returns

Return type

Vector

Adds an integer to each component of a vector

Parameters

b (int32) –

Returns

Return type

Vector

assign(vector)None

Assign the values of the supplied vector.

Parameters

vector (Vector) – Vector to copy values from.

bounded_to_box(box_min, box_max)Vector

Get a copy of this vector, clamped inside of the specified axis aligned cube.

Parameters
Returns

Return type

Vector

Get a copy of this vector, clamped inside of an axis aligned cube centered at the origin.

Parameters

radius (float) – Half size of the cube (or radius of sphere circumscribed in the cube).

Returns

A copy of this vector, bound by cube.

Return type

Vector

clamped_size(min, max)Vector

Create a copy of this vector, with its magnitude/size/length clamped between Min and Max.

Parameters
Returns

Return type

Vector

clamped_size2d(min, max)Vector

Create a copy of this vector, with the 2D magnitude/size/length clamped between Min and Max. Z is unchanged.

Parameters
Returns

Return type

Vector

clamped_size_max(max)Vector

Create a copy of this vector, with its maximum magnitude/size/length clamped to MaxSize.

Parameters

max (float) –

Returns

Return type

Vector

clamped_size_max2d(max)Vector

Create a copy of this vector, with the maximum 2D magnitude/size/length clamped to MaxSize. Z is unchanged.

Parameters

max (float) –

Returns

Return type

Vector

cosine_angle2d(b)float

Returns the cosine of the angle between this vector and another projected onto the XY plane (no Z).

Parameters

b (Vector) – the other vector to find the 2D cosine of the angle with.

Returns

The cosine.

Return type

float

cross(b)Vector

Returns the cross product of two 3d vectors - see http://mathworld.wolfram.com/CrossProduct.html

Parameters

b (Vector) –

Returns

Return type

Vector

direction_unit_to(to)Vector

Find the unit direction vector from one position to another or (0,0,0) if positions are the same.

Parameters

to (Vector) –

Returns

Return type

Vector

distance(v2)float

Distance between two points.

Parameters

v2 (Vector) – The second point.

Returns

The distance between two points.

Return type

float

distance2d(v2)float

Euclidean distance between two points in the XY plane (ignoring Z).

Parameters

v2 (Vector) – The second point.

Returns

The distance between two points in the XY plane.

Return type

float

distance2d_squared(v2)float

Squared euclidean distance between two points in the XY plane (ignoring Z).

Parameters

v2 (Vector) – The second point.

Returns

The distance between two points in the XY plane.

Return type

float

distance_squared(v2)float

Squared distance between two points.

Parameters

v2 (Vector) – The second point.

Returns

The squared distance between two points.

Return type

float

divide(b=[1.0, 1.0, 1.0])Vector

Element-wise Vector division (Result = {A.x/B.x, A.y/B.y, A.z/B.z})

Parameters

b (Vector) –

Returns

Return type

Vector

divide_float(b=1.0)Vector

Vector divide by a float

Parameters

b (float) –

Returns

Return type

Vector

divide_int(b=1)Vector

Vector divide by an integer

Parameters

b (int32) –

Returns

Return type

Vector

dot(b)float

Returns the dot product of two 3d vectors - see http://mathworld.wolfram.com/DotProduct.html

Parameters

b (Vector) –

Returns

Return type

float

equals(b)bool

Returns true if vector A is equal to vector B (A == B)

Parameters

b (Vector) –

Returns

Return type

bool

get_abs()Vector

Get a copy of this vector with absolute value of each component.

Returns

A copy of this vector with absolute value of each component.

Return type

Vector

get_abs_max()float

Find the maximum absolute element (abs(X), abs(Y) or abs(Z)) of a vector

Returns

Return type

float

get_abs_min()float

Find the minimum absolute element (abs(X), abs(Y) or abs(Z)) of a vector

Returns

Return type

float

get_max(b)Vector

Find the maximum elements (X, Y and Z) between the two vector’s components

Parameters

b (Vector) –

Returns

Return type

Vector

get_max_element()float

Find the maximum element (X, Y or Z) of a vector

Returns

Return type

float

get_min(b)Vector

Find the minimum elements (X, Y and Z) between the two vector’s components

Parameters

b (Vector) –

Returns

Return type

Vector

get_min_element()float

Find the minimum element (X, Y or Z) of a vector

Returns

Return type

float

get_projection()Vector

Projects 2D components of vector based on Z.

Returns

Projected version of vector based on Z.

Return type

Vector

get_sign_vector()Vector

Get a copy of the vector as sign only. Each component is set to +1 or -1, with the sign of zero treated as +1.

Returns

Return type

Vector

Convert a direction vector into a ‘heading’ angle.

Returns

Return type

float

interp_spring_to(target, spring_state, stiffness, critical_damping_factor, delta_time, mass=1.000000) -> (Vector, spring_state=VectorSpringState)

Uses a simple spring model to interpolate a vector from Current to Target.

Parameters
• target (Vector) – Target value

• spring_state (VectorSpringState) – Data related to spring model (velocity, error, etc..) - Create a unique variable per spring

• stiffness (float) – How stiff the spring model is (more stiffness means more oscillation around the target value)

• critical_damping_factor (float) – How much damping to apply to the spring (0 means no damping, 1 means critically damped which means no oscillation)

• delta_time (float) –

• mass (float) – Multiplier that acts like mass on a spring

Returns

spring_state (VectorSpringState): Data related to spring model (velocity, error, etc..) - Create a unique variable per spring

Return type

VectorSpringState

interp_to(target, delta_time, interp_speed)Vector

Tries to reach Target based on distance from Current position, giving a nice smooth feeling when tracking a position.

Parameters
• target (Vector) – Target position

• delta_time (float) – Time since last tick

• interp_speed (float) – Interpolation speed, if the speed given is 0, then jump to the target.

Returns

New interpolated position

Return type

Vector

interp_to_constant(target, delta_time, interp_speed)Vector

Tries to reach Target at a constant rate.

Parameters
• target (Vector) – Target position

• delta_time (float) – Time since last tick

• interp_speed (float) – Interpolation speed

Returns

New interpolated position

Return type

Vector

is_nan()bool

Determines if any component is not a number (NAN)

Returns

true if one or more components is NAN, otherwise false.

Return type

bool

is_near_equal(b, error_tolerance=0.0001)bool

Returns true if vector A is equal to vector B (A == B) within a specified error tolerance

Parameters
Returns

Return type

bool

is_nearly_zero(tolerance=0.0001)bool

Checks whether vector is near to zero within a specified tolerance.

Parameters

tolerance (float) – Error tolerance.

Returns

true if vector is in tolerance to zero, otherwise false.

Return type

bool

is_normal()bool

Determines if vector is normalized / unit (length 1).

Returns

true if normalized, false otherwise.

Return type

bool

is_not_near_equal(b, error_tolerance=0.0001)bool

Returns true if vector A is not equal to vector B (A != B) within a specified error tolerance

Parameters
Returns

Return type

bool

is_uniform(tolerance=0.0001)bool

Checks whether all components of this vector are the same, within a tolerance.

Parameters

tolerance (float) – Error tolerance.

Returns

true if the vectors are equal within tolerance limits, false otherwise.

Return type

bool

is_unit(squared_lenth_tolerance=0.0001)bool

Determines if vector is normalized / unit (length 1) within specified squared tolerance.

Parameters

squared_lenth_tolerance (float) –

Returns

true if unit, false otherwise.

Return type

bool

is_zero()bool

Checks whether all components of the vector are exactly zero.

Returns

true if vector is exactly zero, otherwise false.

Return type

bool

length()float

Returns the length of the vector

Returns

Return type

float

length2d()float

Returns the length of the vector’s XY components.

Returns

Return type

float

length2d_squared()float

Returns the squared length of the vector’s XY components.

Returns

Return type

float

length_squared()float

Returns the squared length of the vector

Returns

Return type

float

lerp_to(b, alpha)Vector

Linearly interpolates between A and B based on Alpha (100% of A when Alpha=0 and 100% of B when Alpha=1)

Parameters
Returns

Return type

Vector

linear_color()LinearColor

Converts a vector to LinearColor

Returns

Return type

LinearColor

mirror_by_plane(plane)Vector

Mirrors a vector about a plane.

Parameters

plane (Plane) –

Returns

Mirrored vector.

Return type

Vector

mirror_by_vector(surface_normal)Vector

Given a direction vector and a surface normal, returns the vector reflected across the surface normal. Produces a result like shining a laser at a mirror!

Parameters

surface_normal (Vector) – A normal of the surface the ray should be reflected on.

Returns

Reflected vector.

Return type

Vector

multiply(b)Vector

Element-wise Vector multiplication (Result = {A.x*B.x, A.y*B.y, A.z*B.z})

Parameters

b (Vector) –

Returns

Return type

Vector

multiply_float(b)Vector

Scales Vector A by B

Parameters

b (float) –

Returns

Return type

Vector

multiply_int(b)Vector

Scales Vector A by B

Parameters

b (int32) –

Returns

Return type

Vector

negated()Vector

Negate a vector.

Returns

Return type

Vector

normal(tolerance=0.0001)Vector

Gets a normalized unit copy of the vector, ensuring it is safe to do so based on the length. Returns zero vector if vector length is too small to safely normalize.

Parameters

tolerance (float) – Minimum squared vector length.

Returns

A normalized copy if safe, (0,0,0) otherwise.

Return type

Vector

normal2d(tolerance=0.0001)Vector

Gets a normalized unit copy of the 2D components of the vector, ensuring it is safe to do so. Z is set to zero. Returns zero vector if vector length is too small to normalize.

Parameters

tolerance (float) – Minimum squared vector length.

Returns

Normalized copy if safe, (0,0,0) otherwise.

Return type

Vector

normal_unsafe()Vector

Calculates normalized unit version of vector without checking for zero length.

Returns

Normalized version of vector.

Return type

Vector

normalize(tolerance=0.0)None

Normalize this vector in-place if it is large enough or set it to (0,0,0) otherwise.

Parameters

tolerance (float) – Minimum squared length of vector for normalization.

not_equal(b)bool

Returns true if vector A is not equal to vector B (A != B)

Parameters

b (Vector) –

Returns

Return type

bool

project_on_to(target)Vector

Projects one vector (V) onto another (Target) and returns the projected vector. If Target is nearly zero in length, returns the zero vector.

Parameters

target (Vector) – Vector on which we are projecting.

Returns

V projected on to Target.

Return type

Vector

project_on_to_normal(normal)Vector

Gets a copy of this vector projected onto the input vector, which is assumed to be unit length.

Parameters

normal (Vector) – Vector to project onto (assumed to be unit length).

Returns

Projected vector.

Return type

Vector

project_on_to_plane(plane_normal)Vector

Projects a vector onto a plane defined by a normalized vector (PlaneNormal).

Parameters

plane_normal (Vector) – Normal of the plane.

Returns

Vector projected onto the plane.

Return type

Vector

project_point_on_to_plane(plane_base, plane_normal)Vector

Projects/snaps a point onto a plane defined by a point on the plane and a plane normal.

Parameters
• plane_base (Vector) – A point on the plane.

• plane_normal (Vector) – Normal of the plane.

Returns

Point projected onto the plane.

Return type

Vector

quaternion()Quat

Return the Quaternion orientation corresponding to the direction in which the vector points. Similar to the FRotator version, returns a result without roll such that it preserves the up vector. note: If you don’t care about preserving the up vector and just want the most direct rotation, you can use the faster ‘FQuat::FindBetweenVectors(FVector::ForwardVector, YourVector)’ or ‘FQuat::FindBetweenNormals(…)’ if you know the vector is of unit length.

Returns

Quaternion from the Vector’s direction, without any roll.

Return type

Quat

random_point_in_box_extents(box_extent)Vector

Returns a random point within the specified bounding box using the first vector as an origin and the second as the box extents.

Parameters

box_extent (Vector) –

Returns

Return type

Vector

reciprocal()Vector

Gets the reciprocal of this vector, avoiding division by zero. Zero components are set to BIG_NUMBER.

Returns

Reciprocal of this vector.

Return type

Vector

rotate(b)Vector

Returns result of vector A rotated by Rotator B

Parameters

b (Rotator) –

Returns

Return type

Vector

rotate_angle_axis(angle_deg, axis)Vector

Returns result of vector A rotated by AngleDeg around Axis

Parameters
Returns

Return type

Vector

rotator()Rotator

Return the FRotator orientation corresponding to the direction in which the vector points. Sets Yaw and Pitch to the proper numbers, and sets Roll to zero because the roll can’t be determined from a vector.

Returns

FRotator from the Vector’s direction, without any roll.

Return type

Rotator

rotator_from_axis_and_angle(angle)Rotator

Create a rotation from an this axis and supplied angle (in degrees)

Parameters

angle (float) –

Returns

Return type

Rotator

set(x, y, z)None

Set the values of the vector directly.

Parameters
snapped_to_grid(grid_size)Vector

Gets a copy of this vector snapped to a grid.

Parameters

grid_size (float) – Grid dimension / step.

Returns

A copy of this vector snapped to a grid.

Return type

Vector

subtract(b)Vector

Vector subtraction

Parameters

b (Vector) –

Returns

Return type

Vector

subtract_float(b)Vector

Subtracts a float from each component of a vector

Parameters

b (float) –

Returns

Return type

Vector

subtract_int(b)Vector

Subtracts an integer from each component of a vector

Parameters

b (int32) –

Returns

Return type

Vector

to_degrees()Vector

Converts a vector containing radian values to a vector containing degree values.

Returns

Vector containing degree values

Return type

Vector

Converts a vector containing degree values to a vector containing radian values.

Returns

Return type

Vector

transform()Transform

Convert a vector to a transform. Uses vector as location

Returns

Return type

Transform

truncated()IntVector

Rounds A to an integer with truncation towards zero for each element in a vector. (e.g. -1.7 truncated to -1, 2.8 truncated to 2)

Returns

Return type

IntVector

unit_cartesian_to_spherical()Vector2D

Converts a Cartesian unit vector into spherical coordinates on the unit sphere.

Returns

Output Theta will be in the range [0, PI], and output Phi will be in the range [-PI, PI].

Return type

Vector2D

unrotate(b)Vector

Returns result of vector A rotated by the inverse of Rotator B

Parameters

b (Rotator) –

Returns

Return type

Vector

unwind_euler()None

When this vector contains Euler angles (degrees), ensure that angles are between +/-180

vector2d()Vector2D

Convert a Vector to a Vector2D using the Vector’s (X, Y) coordinates

Returns

Return type

Vector2D

property x

Type

(float)

property y