struct Vector2

in global

A 2-dimensional vector. Typically represents a position or size in 2D space.


public float x { get; set; }

X component of this Vector.

public float y { get; set; }

Y component of this Vector.

public Vector2( float x, float y )

Initializes a 2D vector with given components.

  • x The X component.
  • y The Y component.

public Vector2( float all )

Initializes the vector with all components set to the given value.

public Vector2( Vector3 v )

Initializes the 2D vector with components from given 3D vector, discarding the Z component.

public static Vector2 One { get; }

Returns a 2D vector with every component set to 1

public static Vector2 Zero { get; }

Returns a 2D vector with every component set to 0

public static Vector2 Up { get; }

Returns a 2D vector with Y set to 1. This represents the upwards direction in 2D space.

public static Vector2 Down { get; }

Returns a 2D vector with Y set to -1. This represents the downwards direction in 2D space.

public static Vector2 Left { get; }

Returns a 2D vector with X set to 1. This represents the left hand direction in 2D space.

public static Vector2 Right { get; }

Returns a 2D vector with X set to -1. This represents the right hand direction in 2D space.

public static Vector2 Random { get; }

Uniformly samples a 2D position from all points with distance at most 1 from the origin.

public float Length { get; }

Returns the magnitude of the vector

public float LengthSquared { get; }

This is faster than Length, so is better to use in certain circumstances

public Vector2 Perpendicular { get; }

Returns a vector that runs perpendicular to this one

public bool IsNearZeroLength { get; }

Returns true if the squared length is less than 1e-8 (which is really near zero)

public Vector2 Normal { get; }

Return the same vector but with a length of one

public float Degrees { get; }

Return the angle of this vector in degrees, always between 0 and 360

public static Vector2 FromRadians( float radians )

Returns a point on a circle at given rotation from X axis, counter clockwise.

public static Vector2 FromDegrees( float degrees )

Returns a point on a circle at given rotation from X axis, counter clockwise.

public static float DistanceBetween( Vector2 a, Vector2 b )

Returns distance between the 2 given vectors.

public static float Distance( ref Vector2 a, ref Vector2 b )

Returns distance between the 2 given vectors.

public float Distance( Vector2 target )

Returns distance between this and given vectors.

public static float DistanceBetweenSquared( Vector2 a, Vector2 b )

Returns squared distance between the 2 given vectors. This is faster than DistanceBetween, and can be used for things like comparing distances, as long as only squared values are used.

public static float DistanceSquared( ref Vector2 a, ref Vector2 b )

Returns squared distance between the 2 given vectors. This is faster than DistanceBetween, and can be used for things like comparing distances, as long as only squared values are used.

public float DistanceSquared( Vector2 target )

Returns squared distance between the 2 given vectors. This is faster than Distance, and can be used for things like comparing distances, as long as only squared values are used.

public static float Dot( Vector2 a, Vector2 b )

Returns dot product between the 2 given vectors.

public bool AlmostEqual( Vector2 v, float delta = 0.0001 )

Returns true if we're nearly equal to the passed vector.

  • v The value to compare with
  • delta The max difference between component values
  • Returns True if nearly equal

public Vector2 SnapToGrid( float gridSize, bool sx = True, bool sy = True )

Snap to grid along all 3 axes.

public Vector2 WithX( float x )

Return this vector with given X.

public Vector2 WithY( float y )

Return this vector with given Y.

public static Vector2 Lerp( Vector2 a, Vector2 b, float frac, bool clamp = True )

Linearly interpolate from point a to point b.

public Vector2 LerpTo( Vector2 target, float t, bool clamp = True )

Linearly interpolate from this vector to given vector.

public static Vector2 Lerp( Vector2 a, Vector2 b, Vector2 t, bool clamp = True )

Linearly interpolate from point a to point b with separate fraction for each axis.

public Vector2 LerpTo( Vector2 target, Vector2 t, bool clamp = True )

Linearly interpolate from this vector to given vector with separate fraction for each axis.

public Vector2 Clamp( Vector2 otherMin, Vector2 otherMax )

Returns a vector each axis of which is clamped to between the 2 given vectors. Basically clamps a point to a square.

  • otherMin The mins vector. Values on each axis should be smaller than those of the maxs vector.
  • otherMax The maxs vector. Values on each axis should be bigger than those of the mins vector.

public Vector2 Clamp( float min, float max )

Returns a vector each axis of which is clamped to given min and max values.

  • min Minimum value for each axis.
  • max Maximum value for each axis.

public Vector2 ComponentMin( Vector2 other )

Returns a vector that has the minimum values on each axis between this vector and given vector.

public static Vector2 Min( Vector2 a, Vector2 b )

Returns a vector that has the minimum values on each axis between the 2 given vectors.

public Vector2 ComponentMax( Vector2 other )

Returns a vector that has the maximum values on each axis between this vector and given vector.

public static Vector2 Max( Vector2 a, Vector2 b )

Returns a vector that has the maximum values on each axis between the 2 given vectors.

public static Vector2 Direction( ref Vector2 from, ref Vector2 to )

Calculates the normalized direction vector from one point to another in 2D space.

public static Vector2 Parse( string str )

Given a string, try to convert this into a Vector2. Example formatting is "x,y", "[x,y]", "x y", etc.

public static bool TryParse( string str, ref Vector2 result )

🤡 Doc inheritance is not yet supported.

No summary.

public static Vector2 Parse( string str, IFormatProvider provider )

🤡 Doc inheritance is not yet supported.

No summary.

public static bool TryParse( string str, IFormatProvider provider, ref Vector2 result )

🤡 Doc inheritance is not yet supported.

No summary.

public string ToString( )

😔 No documentation found.

public static Vector2 op_Division( Vector2 c1, float c2 )

😔 No documentation found.

public Type GetType( )

😔 No documentation found.

public int GetHashCode( )

😔 No documentation found.

public bool Equals( Vector2 o )

😔 No documentation found.

public bool Equals( object obj )

😔 No documentation found.

public static bool op_Inequality( Vector2 left, Vector2 right )

😔 No documentation found.

public static bool op_Equality( Vector2 left, Vector2 right )

😔 No documentation found.

public static Vector2 op_Division( Vector2 c1, Vector2 c2 )

😔 No documentation found.

public Vector2( Vector2 v )

😔 No documentation found.

public static Vector2 op_Multiply( float f, Vector2 c1 )

😔 No documentation found.

public static Vector2 op_Multiply( Vector2 c1, float f )

😔 No documentation found.

public static Vector2 op_UnaryNegation( Vector2 c1 )

😔 No documentation found.

public static Vector2 op_Addition( Vector2 c1, Vector2 c2 )

😔 No documentation found.

public static Vector2 op_Implicit( double value )

😔 No documentation found.

public static Vector4 op_Implicit( Vector2 value )

😔 No documentation found.

public static Vector2 op_Implicit( Vector3 value )

😔 No documentation found.

public static Vector2 op_Implicit( Vector2 value )

😔 No documentation found.

public static Vector2 op_Implicit( Vector2 value )

😔 No documentation found.

public Vector2 Abs( )

😔 No documentation found.

public static Vector2 op_Multiply( Vector2 c1, Vector2 c2 )

😔 No documentation found.

public static Vector2 op_Subtraction( Vector2 c1, Vector2 c2 )

😔 No documentation found.