reckfellENGINE

Vector2

A two-component value for 2D coordinates and calculations.

On this page
struct Vector2ReckfellSharpInherits ValueType

A Vector2 may mean a point, displacement, velocity or direction. Subtract positions in the same space for aiming; normalize only when unit length is required. Normalized of zero returns Zero but does not define a direction.

Ordinary 2D has X right and Y down, so Right.AngleTo(Down) = π/2 appears clockwise. Use Bounce with a unit surface normal for bouncing; this SDK Reflect gives the opposite result. This value neither moves a physics body nor queries collisions.

Practical guide.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

Vector2Constructor
# Vector2
C#
public Vector2(float x, float y);

Constructs a new Vector2 from the given Vector2.X and Vector2.Y.

Parameters
NameTypeDefault
xfloat—
yfloat—
x

The vector's X component.

y

The vector's Y component.

Properties8

DownProperty
# Down
C#
public static Vector2 Down { get; }

Down unit vector. Y is down in 2D, so this vector points +Y.

InfProperty
# Inf
C#
public static Vector2 Inf { get; }

Infinity vector, a vector with all components set to @C#.INF.

ItemProperty
# Item
C#
public float this[int index] { get; set; }

Access vector components using their index.

LeftProperty
# Left
C#
public static Vector2 Left { get; }

Left unit vector. Represents the direction of left.

OneProperty
# One
C#
public static Vector2 One { get; }

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

RightProperty
# Right
C#
public static Vector2 Right { get; }

Right unit vector. Represents the direction of right.

UpProperty
# Up
C#
public static Vector2 Up { get; }

Up unit vector. Y is down in 2D, so this vector points -Y.

ZeroProperty
# Zero
C#
public static Vector2 Zero { get; }

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

Methods72

AbsVector2
# Abs
C#
public Vector2 Abs();

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

Returns Vector2

A vector with Mathf.Abs called on each component.

Anglefloat
# Angle
C#
public float Angle();

Returns Mathf.Atan2(Y, X): the angle in radians relative to the positive X axis. Right has angle 0, and Down (positive Y in the usual 2D screen coordinates) has angle PI / 2.

Returns float

The angle of this vector, in radians.

AngleTofloat
# AngleTo
C#
public float AngleTo(Vector2 to);

Returns a signed radian angle using atan2(Cross, Dot). Right → Down gives π/2, clockwise on a Y-down screen.

Parameters
NameTypeDefault
toVector2—
to

Other nonzero direction in the same space; normalization is optional.

Returns float

Signed angle atan2(Cross(to), Dot(to)) in radians. A zero vector has no geometric direction.

AngleToPointfloat
# AngleToPoint
C#
public float AngleToPoint(Vector2 to);

Returns Mathf.Atan2(to.Y - Y, to.X - X), the angle in radians of the direction from this point to to. Both points must use the same coordinate system. This does not rotate an Entity or measure an angle between two independent direction vectors.

Parameters
NameTypeDefault
toVector2—
to

The other vector to compare this vector to.

Returns float

The angle between the two vectors, in radians.

Aspectfloat
# Aspect
C#
public float Aspect();

Returns this vector's aspect ratio, which is Vector2.X divided by Vector2.Y.

Returns float

The Vector2.X component divided by the Vector2.Y component.

BezierDerivativeVector2
# BezierDerivative
C#
public Vector2 BezierDerivative(Vector2 control1, Vector2 control2, Vector2 end, float t);

Returns the derivative at the given t on the Bézier curve defined by this vector and the given control_1, control_2, and end points.

Parameters
NameTypeDefault
control1Vector2—
control2Vector2—
endVector2—
tfloat—
control1

Control point that defines the bezier curve.

control2

Control point that defines the bezier curve.

end

The destination value for the interpolation.

t

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Vector2

The resulting value of the interpolation.

BezierInterpolateVector2
# BezierInterpolate
C#
public Vector2 BezierInterpolate(Vector2 control1, Vector2 control2, Vector2 end, float t);

Returns the point at the given t on the Bézier curve defined by this vector and the given control_1, control_2, and end points.

Parameters
NameTypeDefault
control1Vector2—
control2Vector2—
endVector2—
tfloat—
control1

Control point that defines the bezier curve.

control2

Control point that defines the bezier curve.

end

The destination vector.

t

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Vector2

The interpolated vector.

BounceVector2
# Bounce
C#
public Vector2 Bounce(Vector2 normal);

Bounces velocity off a surface with a unit normal. (1,1) and Up produce (1,−1), opposite to this SDK Reflect result.

Parameters
NameTypeDefault
normalVector2—
normal

The normal vector defining the plane to bounce off. Must be normalized.

Returns Vector2

The bounced vector.

CeilVector2
# Ceil
C#
public Vector2 Ceil();

Returns a new vector with all components rounded up (towards positive infinity).

Returns Vector2

A vector with Mathf.Ceil called on each component.

Clamp2 overloads
# Clamp · 1/2
C#
public Vector2 Clamp(Vector2 min, Vector2 max);

Returns a new vector with all components clamped between the components of Vector2.Min and Vector2.Max, by running @GlobalScope.clamp on each component.

Parameters
NameTypeDefault
minVector2—
maxVector2—
min

The vector with minimum allowed values.

max

The vector with maximum allowed values.

Returns Vector2

The vector with all components clamped.

# Clamp · 2/2
C#
public Vector2 Clamp(float min, float max);

Returns a new vector with all components clamped between the components of Vector2.Min and Vector2.Max, by running @GlobalScope.clamp on each component.

Parameters
NameTypeDefault
minfloat—
maxfloat—
min

The minimum allowed value.

max

The maximum allowed value.

Returns Vector2

The vector with all components clamped.

Crossfloat
# Cross
C#
public float Cross(Vector2 with);

Returns scalar x₁y₂ − y₁x₂, not Vector3. Right.Cross(Down) = 1. Interpret its sign with the screen Y convention.

Parameters
NameTypeDefault
withVector2—
with

The other vector.

Returns float

The cross product value.

CubicInterpolateVector2
# CubicInterpolate
C#
public Vector2 CubicInterpolate(Vector2 b, Vector2 preA, Vector2 postB, float weight);

Performs a cubic interpolation between this vector and b using pre_a and post_b as handles, and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.

Parameters
NameTypeDefault
bVector2—
preAVector2—
postBVector2—
weightfloat—
b

The destination vector.

preA

A vector before this vector.

postB

A vector after b.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Vector2

The interpolated vector.

CubicInterpolateInTimeVector2
# CubicInterpolateInTime
C#
public Vector2 CubicInterpolateInTime(Vector2 b, Vector2 preA, Vector2 postB, float weight, float t, float preAT, float postBT);

Performs a cubic interpolation between this vector and b using pre_a and post_b as handles, and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation. It can perform smoother interpolation than Vector2.CubicInterpolate by the time values.

Parameters
NameTypeDefault
bVector2—
preAVector2—
postBVector2—
weightfloat—
tfloat—
preATfloat—
postBTfloat—
b

The destination vector.

preA

A vector before this vector.

postB

A vector after b.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Vector2

The interpolated vector.

Deconstructvoid
# Deconstruct
C#
public void Deconstruct(out float x, out float y);

Helper method for deconstruction into a tuple.

Parameters
NameTypeDefault
xfloat—
yfloat—
DirectionToVector2
# DirectionTo
C#
public Vector2 DirectionTo(Vector2 to);

Returns the normalized vector pointing from this vector to to. a.direction_to(b) is equivalent to (b - a).normalized(). See also Vector2.Normalized.

Parameters
NameTypeDefault
toVector2—
to

The other vector to point towards.

Returns Vector2

The direction from this vector to to.

DistanceSquaredTofloat
# DistanceSquaredTo
C#
public float DistanceSquaredTo(Vector2 to);

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

Parameters
NameTypeDefault
toVector2—
to

The other vector to use.

Returns float

The squared distance between the two vectors.

DistanceTofloat
# DistanceTo
C#
public float DistanceTo(Vector2 to);

Returns the Euclidean distance between this vector and to.

Parameters
NameTypeDefault
toVector2—
to

The other vector to use.

Returns float

The distance between the two vectors.

Dotfloat
# Dot
C#
public float Dot(Vector2 with);

Dot product. For unit directions it is the angle cosine; otherwise it also includes both magnitudes.

Parameters
NameTypeDefault
withVector2—
with

The other vector to use.

Returns float

The dot product of the two vectors.

Equals2 overloads
# Equals · 1/2
C#
public bool Equals(Vector2 other);

Returns true if the vectors are exactly equal. Note: Due to floating-point precision errors, consider using Vector2.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
otherVector2—
other

The other vector.

Returns bool

Whether or not the vectors are exactly equal.

# Equals · 2/2
C#
public override bool Equals(object? obj);

Returns true if the vector is exactly equal to the given object (obj). Note: Due to floating-point precision errors, consider using Vector2.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
objobject—
obj

The object to compare with.

Returns bool

Whether or not the vector and the object are equal.

FloorVector2
# Floor
C#
public Vector2 Floor();

Returns a new vector with all components rounded down (towards negative infinity).

Returns Vector2

A vector with Mathf.Floor called on each component.

FromAngleVector2
# FromAngle
C#
public static Vector2 FromAngle(float angle);

Creates a Vector2 rotated to the given Vector2.Angle in radians. This is equivalent to doing Vector2(cos(angle), sin(angle)) or Vector2.RIGHT.rotated(angle).

Text
print(Vector2.from_angle(0)) # Prints (1.0, 0.0)
print(Vector2(1, 0).angle()) # Prints 0.0, which is the angle used above.
print(Vector2.from_angle(PI / 2)) # Prints (0.0, 1.0)

Note: The length of the returned Vector2 is approximately 1.0, but is is not guaranteed to be exactly 1.0 due to floating-point precision issues. Call Vector2.Normalized on the returned Vector2 if you require a unit vector.

Parameters
NameTypeDefault
anglefloat—
angle

Angle of the vector, in radians.

Returns Vector2

The resulting vector.

GetHashCodeint
# GetHashCode
C#
public override int GetHashCode();

Serves as the hash function for Vector2.

Returns int

A hash code for this vector.

InverseVector2
# Inverse
C#
public Vector2 Inverse();

Returns the inverse of the vector. This is the same as Vector2(1.0 / v.x, 1.0 / v.y).

Returns Vector2

The inverse of this vector.

IsEqualApproxbool
# IsEqualApprox
C#
public bool IsEqualApprox(Vector2 other);

Returns true if this vector and to are approximately equal, by running @GlobalScope.is_equal_approx on each component.

Parameters
NameTypeDefault
otherVector2—
other

The other vector to compare.

Returns bool

Whether or not the vectors are approximately equal.

IsFinitebool
# IsFinite
C#
public bool IsFinite();

Returns true if this vector is finite, by calling @GlobalScope.is_finite on each component.

Returns bool

Whether this vector is finite or not.

IsNormalizedbool
# IsNormalized
C#
public bool IsNormalized();

Returns true if the vector is normalized, i.e. its length is approximately equal to 1.

Returns bool

A bool indicating whether or not the vector is normalized.

IsZeroApproxbool
# IsZeroApprox
C#
public bool IsZeroApprox();

Returns true if this vector's values are approximately zero, by running @GlobalScope.is_zero_approx on each component. This method is faster than using Vector2.IsEqualApprox with one value as a zero vector.

Returns bool

Whether or not the vector is approximately zero.

Lengthfloat
# Length
C#
public float Length();

Returns the length (magnitude) of this vector.

Returns float

The length of this vector.

LengthSquaredfloat
# LengthSquared
C#
public float LengthSquared();

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

Returns float

The squared length of this vector.

LerpVector2
# Lerp
C#
public Vector2 Lerp(Vector2 to, float weight);

Interpolates linearly by weight. 0/1 give endpoints; out-of-range values can extrapolate. Weight is neither distance nor time.

Parameters
NameTypeDefault
toVector2—
weightfloat—
to

The destination vector for interpolation.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Vector2

The resulting vector of the interpolation.

LimitLengthVector2
# LimitLength
C#
public Vector2 LimitLength(float length = 1f);

Returns the vector with a maximum length by limiting its length to Vector2.Length. If the vector is non-finite, the result is undefined.

Parameters
NameTypeDefault
lengthfloat1f
length

The length to limit to.

Returns Vector2

The vector with its length limited.

Max2 overloads
# Max · 1/2
C#
public Vector2 Max(Vector2 with);

Returns the component-wise maximum of this and with, equivalent to Vector2(maxf(x, with.x), maxf(y, with.y)).

Parameters
NameTypeDefault
withVector2—
with

The other vector to use.

Returns Vector2

The resulting maximum vector.

# Max · 2/2
C#
public Vector2 Max(float with);

Returns the component-wise maximum of this and with, equivalent to Vector2(maxf(x, with.x), maxf(y, with.y)).

Parameters
NameTypeDefault
withfloat—
with

The other value to use.

Returns Vector2

The resulting maximum vector.

MaxAxisIndexVector2.Axis
# MaxAxisIndex
C#
public Vector2.Axis MaxAxisIndex();

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

Returns Vector2.Axis

The index of the highest axis.

Min2 overloads
# Min · 1/2
C#
public Vector2 Min(Vector2 with);

Returns the component-wise minimum of this and with, equivalent to Vector2(minf(x, with.x), minf(y, with.y)).

Parameters
NameTypeDefault
withVector2—
with

The other vector to use.

Returns Vector2

The resulting minimum vector.

# Min · 2/2
C#
public Vector2 Min(float with);

Returns the component-wise minimum of this and with, equivalent to Vector2(minf(x, with.x), minf(y, with.y)).

Parameters
NameTypeDefault
withfloat—
with

The other value to use.

Returns Vector2

The resulting minimum vector.

MinAxisIndexVector2.Axis
# MinAxisIndex
C#
public Vector2.Axis MinAxisIndex();

Returns the axis of the vector's lowest value. See AXIS_* constants. If all components are equal, this method returns Vector2.Axis.Y.

Returns Vector2.Axis

The index of the lowest axis.

MoveTowardVector2
# MoveToward
C#
public Vector2 MoveToward(Vector2 to, float delta);

For finite delta ≥ 0, approaches without overshoot; a distance below Mathf.Epsilon snaps to the target. Negative delta normally moves away. For speed per second, pass speed × timestep.

Parameters
NameTypeDefault
toVector2—
deltafloat—
to

Target value in the same coordinate space.

delta

Finite nonnegative step distance in vector units, for example speed × deltaTime. This is not a number of seconds.

Returns Vector2

New value; reaching the target or a distance below Mathf.Epsilon returns exactly to. The original vector is unchanged.

NormalizedVector2
# Normalized
C#
public Vector2 Normalized();

Returns unit direction, or Zero for a zero vector. Removes displacement magnitude; Zero does not define an aiming angle.

Returns Vector2

A unit-length copy for a nonzero vector, or Zero. The original value is unchanged.

OrthogonalVector2
# Orthogonal
C#
public Vector2 Orthogonal();

Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.

Returns Vector2

The perpendicular vector.

PosMod2 overloads
# PosMod · 1/2
C#
public Vector2 PosMod(Vector2 modv);

Returns a vector composed of the @GlobalScope.fposmod of this vector's components and mod.

Parameters
NameTypeDefault
modvVector2—
modv

A vector representing the divisors of the operation.

Returns Vector2

A vector with each component Mathf.PosMod by modv's components.

# PosMod · 2/2
C#
public Vector2 PosMod(float mod);

Returns a vector composed of the @GlobalScope.fposmod of this vector's components and mod.

Parameters
NameTypeDefault
modfloat—
mod

A value representing the divisor of the operation.

Returns Vector2

A vector with each component Mathf.PosMod by mod.

ProjectVector2
# Project
C#
public Vector2 Project(Vector2 onNormal);

Returns a new vector resulting from projecting this vector onto the given vector b. The resulting new vector is parallel to b. See also Vector2.Slide. Note: If the vector b is a zero vector, the components of the resulting new vector will be @C#.NAN.

Parameters
NameTypeDefault
onNormalVector2—
onNormal

The vector to project onto.

Returns Vector2

The projected vector.

ReflectVector2
# Reflect
C#
public Vector2 Reflect(Vector2 normal);

Computes 2 × dot(v,n) × n − v for unit n. This is negative Bounce; use Bounce for ordinary surface bouncing.

Parameters
NameTypeDefault
normalVector2—
normal

The normal vector defining the plane to reflect from. Must be normalized.

Returns Vector2

The reflected vector.

RotatedVector2
# Rotated
C#
public Vector2 Rotated(float angle);

Returns the result of rotating this vector by Vector2.Angle (in radians). See also @GlobalScope.deg_to_rad.

Parameters
NameTypeDefault
anglefloat—
angle

The angle to rotate by, in radians.

Returns Vector2

The rotated vector.

RoundVector2
# Round
C#
public Vector2 Round();

Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.

Returns Vector2

The rounded vector.

SignVector2
# Sign
C#
public Vector2 Sign();

Returns a new vector with each component set to 1.0 if it's positive, -1.0 if it's negative, and 0.0 if it's zero. The result is identical to calling @GlobalScope.sign on each component.

Returns Vector2

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

SlerpVector2
# Slerp
C#
public Vector2 Slerp(Vector2 to, float weight);

Returns the result of spherical linear interpolation between this vector and to, by amount weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation. This method also handles interpolating the lengths if the input vectors have different lengths. For the special case of one or both input vectors having zero length, this method behaves like Vector2.Lerp.

Parameters
NameTypeDefault
toVector2—
weightfloat—
to

The destination vector for interpolation.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Vector2

The resulting vector of the interpolation.

SlideVector2
# Slide
C#
public Vector2 Slide(Vector2 normal);

Returns a new vector resulting from sliding this vector along a line with normal n. The resulting new vector is perpendicular to n, and is equivalent to this vector minus its projection on n. See also Vector2.Project. Note: The vector n must be normalized. See also Vector2.Normalized.

Parameters
NameTypeDefault
normalVector2—
normal

The normal vector of the plane to slide on.

Returns Vector2

The slid vector.

Snapped2 overloads
# Snapped · 1/2
C#
public Vector2 Snapped(Vector2 step);

Returns a new vector with each component snapped to the nearest multiple of the corresponding component in step. This can also be used to round the components to an arbitrary number of decimals.

Parameters
NameTypeDefault
stepVector2—
step

A vector value representing the step size to snap to.

Returns Vector2

The snapped vector.

# Snapped · 2/2
C#
public Vector2 Snapped(float step);

Returns a new vector with each component snapped to the nearest multiple of the corresponding component in step. This can also be used to round the components to an arbitrary number of decimals.

Parameters
NameTypeDefault
stepfloat—
step

The step size to snap to.

Returns Vector2

The snapped vector.

ToString2 overloads
# ToString · 1/2
C#
public override string ToString();

Converts this Vector2 to a string.

Returns string

A string representation of this vector.

# ToString · 2/2
C#
public string ToString(string? format);

Converts this Vector2 to a string with the given format.

Parameters
NameTypeDefault
formatstring—
Returns string

A string representation of this vector.

op_AdditionVector2
# op_Addition
C#
public static Vector2 operator +(Vector2 left, Vector2 right);

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

Parameters
NameTypeDefault
leftVector2—
rightVector2—
left

The left vector.

right

The right vector.

Returns Vector2

The added vector.

op_Division2 overloads
# op_Division · 1/2
C#
public static Vector2 operator /(Vector2 vec, Vector2 divisorv);

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

Parameters
NameTypeDefault
vecVector2—
divisorvVector2—
vec

The dividend vector.

divisorv

The divisor vector.

Returns Vector2

The divided vector.

# op_Division · 2/2
C#
public static Vector2 operator /(Vector2 vec, float divisor);

Divides each component of the Vector2 by the given System.Single.

Parameters
NameTypeDefault
vecVector2—
divisorfloat—
vec

The dividend vector.

divisor

The divisor value.

Returns Vector2

The divided vector.

op_Equalitybool
# op_Equality
C#
public static bool operator ==(Vector2 left, Vector2 right);

Returns true if the vectors are exactly equal. Note: Due to floating-point precision errors, consider using Vector2.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
leftVector2—
rightVector2—
left

The left vector.

right

The right vector.

Returns bool

Whether or not the vectors are exactly equal.

op_GreaterThanbool
# op_GreaterThan
C#
public static bool operator >(Vector2 left, Vector2 right);

Compares two Vector2 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. This operator is useful for sorting vectors.

Parameters
NameTypeDefault
leftVector2—
rightVector2—
left

The left vector.

right

The right vector.

Returns bool

Whether or not the left is greater than the right.

op_GreaterThanOrEqualbool
# op_GreaterThanOrEqual
C#
public static bool operator >=(Vector2 left, Vector2 right);

Compares two Vector2 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. This operator is useful for sorting vectors.

Parameters
NameTypeDefault
leftVector2—
rightVector2—
left

The left vector.

right

The right vector.

Returns bool

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

op_Inequalitybool
# op_Inequality
C#
public static bool operator !=(Vector2 left, Vector2 right);

Returns true if the vectors are not equal. Note: Due to floating-point precision errors, consider using Vector2.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
leftVector2—
rightVector2—
left

The left vector.

right

The right vector.

Returns bool

Whether or not the vectors are not equal.

op_LessThanbool
# op_LessThan
C#
public static bool operator <(Vector2 left, Vector2 right);

Compares two Vector2 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. This operator is useful for sorting vectors.

Parameters
NameTypeDefault
leftVector2—
rightVector2—
left

The left vector.

right

The right vector.

Returns bool

Whether or not the left is less than the right.

op_LessThanOrEqualbool
# op_LessThanOrEqual
C#
public static bool operator <=(Vector2 left, Vector2 right);

Compares two Vector2 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. This operator is useful for sorting vectors.

Parameters
NameTypeDefault
leftVector2—
rightVector2—
left

The left vector.

right

The right vector.

Returns bool

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

op_Modulus2 overloads
# op_Modulus · 1/2
C#
public static Vector2 operator %(Vector2 vec, Vector2 divisorv);

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

Parameters
NameTypeDefault
vecVector2—
divisorvVector2—
vec

The dividend vector.

divisorv

The divisor vector.

Returns Vector2

The remainder vector.

# op_Modulus · 2/2
C#
public static Vector2 operator %(Vector2 vec, float divisor);

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

Parameters
NameTypeDefault
vecVector2—
divisorfloat—
vec

The dividend vector.

divisor

The divisor value.

Returns Vector2

The remainder vector.

op_Multiply3 overloads
# op_Multiply · 1/3
C#
public static Vector2 operator *(Vector2 left, Vector2 right);

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

Parameters
NameTypeDefault
leftVector2—
rightVector2—
left

The left vector.

right

The right vector.

Returns Vector2

The multiplied vector.

# op_Multiply · 2/3
C#
public static Vector2 operator *(Vector2 vec, float scale);

Multiplies each component of the Vector2 by the given System.Single.

Parameters
NameTypeDefault
vecVector2—
scalefloat—
vec

The vector to multiply.

scale

The scale to multiply by.

Returns Vector2

The multiplied vector.

# op_Multiply · 3/3
C#
public static Vector2 operator *(float scale, Vector2 vec);

Multiplies each component of the Vector2 by the given System.Single.

Parameters
NameTypeDefault
scalefloat—
vecVector2—
scale

The scale to multiply by.

vec

The vector to multiply.

Returns Vector2

The multiplied vector.

op_SubtractionVector2
# op_Subtraction
C#
public static Vector2 operator -(Vector2 left, Vector2 right);

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

Parameters
NameTypeDefault
leftVector2—
rightVector2—
left

The left vector.

right

The right vector.

Returns Vector2

The subtracted vector.

op_UnaryNegationVector2
# op_UnaryNegation
C#
public static Vector2 operator -(Vector2 vec);

Returns the negative value of the Vector2. This is the same as writing new Vector2(-v.X, -v.Y). This operation flips the direction of the vector while keeping the same magnitude. With floats, the number zero can be either positive or negative.

Parameters
NameTypeDefault
vecVector2—
vec

The vector to negate/flip.

Returns Vector2

The negated/flipped vector.

op_UnaryPlusVector2
# op_UnaryPlus
C#
public static Vector2 operator +(Vector2 vec);

Returns the same value as if the + was not there. Unary + does nothing, but sometimes it can make your code more readable.

Parameters
NameTypeDefault
vecVector2—
vec

The vector to do nothing to.

Returns Vector2

The original vector.

Fields and constants2

XField
# X
C#
public float X;

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

YField
# Y
C#
public float Y;

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

Vector2.Axis

ValueDescription
X = 0

Enumerated value for the X axis. Returned by Vector2.MaxAxisIndex and Vector2.MinAxisIndex.

Y = 1

Enumerated value for the Y axis. Returned by Vector2.MaxAxisIndex and Vector2.MinAxisIndex.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.