Summary

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

Constructors

Vector2 Initializes a 2D vector with given components.

Properties

Degrees Return the angle of this vector in degrees, always between 0 and 360
IsNearZeroLength Returns true if the squared length is less than 1e-8 (which is really near zero)
Length Returns the magnitude of the vector
LengthSquared This is faster than Length, so is better to use in certain circumstances
Normal Return the same vector but with a length of one
Perpendicular Returns a vector that runs perpendicular to this one
x X component of this Vector.
y Y component of this Vector.

Methods

Abs Returns a new vector with all values positive. -5 becomes 5, etc.
AlmostEqual Returns true if we're nearly equal to the passed vector.
Clamp Returns a vector each axis of which is clamped to between the 2 given vectors. Basically clamps a point to a square.
ComponentMax Returns a vector that has the maximum values on each axis between this vector and given vector.
ComponentMin Returns a vector that has the minimum values on each axis between this vector and given vector.
LerpTo Linearly interpolate from this vector to given vector.
SnapToGrid Snap to grid along all 3 axes.
WithX Return this vector with given X.
WithY Return this vector with given Y.

Static Properties

Down Returns a 2D vector with Y set to -1. This represents the downwards direction in 2D space.
Left Returns a 2D vector with X set to 1. This represents the left hand direction in 2D space.
One Returns a 2D vector with every component set to 1
Random Uniformly samples a 2D position from all points with distance at most 1 from the origin.
Right Returns a 2D vector with X set to -1. This represents the right hand direction in 2D space.
Up Returns a 2D vector with Y set to 1. This represents the upwards direction in 2D space.
Zero Returns a 2D vector with every component set to 0

Static Methods

Direction Calculates the normalized direction vector from one point to another in 2D space.
Distance Returns distance between the 2 given vectors.
DistanceBetween Returns distance between the 2 given vectors.
DistanceBetweenSquared Returns squared distance between the 2 given vectors. This is faster than <see cref="M:Vector2.DistanceBetween(Vector2,Vector2)">DistanceBetween</see>, and can be used for things like comparing distances, as long as only squared values are used.
DistanceSquared Returns squared distance between the 2 given vectors. This is faster than <see cref="M:Vector2.DistanceBetween(Vector2,Vector2)">DistanceBetween</see>, and can be used for things like comparing distances, as long as only squared values are used.
Dot Returns dot product between the 2 given vectors.
FromDegrees Returns a point on a circle at given rotation from X axis, counter clockwise.
FromRadians Returns a point on a circle at given rotation from X axis, counter clockwise.
Lerp Linearly interpolate from point a to point b.
Max Returns a vector that has the maximum values on each axis between the 2 given vectors.
Min Returns a vector that has the minimum values on each axis between the 2 given vectors.
Parse Given a string, try to convert this into a Vector2. Example formatting is "x,y", "[x,y]", "x y", etc.
TryParse
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.