# Vector2

A 2-dimensional vector. Typically represents a position, size, or direction in 2D space.

- Kind: struct
- Assembly: `Sandbox.System`
- Modifiers: sealed

## Constructors

- [`Vector2`](/api/Vector2/.ctor): Initializes a 2D vector with given components.

## Properties

- [`Degrees`](/api/Vector2/Degrees): Return the angle of this vector in degrees, always between 0 and 360
- [`Down`](/api/Vector2/Down): Returns a 2D vector with Y set to 1. This typically represents down in 2D space.
- [`Inverse`](/api/Vector2/Inverse): Returns the inverse of this vector, which is useful for scaling vectors
- [`IsInfinity`](/api/Vector2/IsInfinity): Returns true if x, y, or z are infinity
- [`IsNaN`](/api/Vector2/IsNaN): Returns true if x, y, or z are NaN
- [`IsNearZeroLength`](/api/Vector2/IsNearZeroLength): Returns true if the squared length is less than 1e-8 (which is really near zero)
- [`Item`](/api/Vector2/Item)
- [`Left`](/api/Vector2/Left): Returns a 2D vector with X set to -1. This typically represents the left hand direction in 2D space.
- [`Length`](/api/Vector2/Length): Returns the magnitude of the vector
- [`LengthSquared`](/api/Vector2/LengthSquared): This is faster than Length, so is better to use in certain circumstances
- [`Normal`](/api/Vector2/Normal): Return the same vector but with a length of one
- [`One`](/api/Vector2/One): Returns a 2D vector with every component set to 1
- [`Perpendicular`](/api/Vector2/Perpendicular): Returns a vector that runs perpendicular to this one
- [`Random`](/api/Vector2/Random): Uniformly samples a 2D position from all points with distance at most 1 from the origin.
- [`Right`](/api/Vector2/Right): Returns a 2D vector with X set to 1. This typically represents the right hand direction in 2D space.
- [`Up`](/api/Vector2/Up): Returns a 2D vector with Y set to -1. This typically represents up in 2D space.
- [`x`](/api/Vector2/x): X component of this vector.
- [`y`](/api/Vector2/y): Y component of this vector.
- [`Zero`](/api/Vector2/Zero): Returns a 2D vector with every component set to 0

## Methods

- [`Abs`](/api/Vector2/Abs): Returns a new vector with all values positive. -5 becomes 5, etc.
- [`AddClamped`](/api/Vector2/AddClamped): Try to add to this vector. If we're already over max then don't add. If we're over max when we add, clamp in that direction so we're not.
- [`AlmostEqual`](/api/Vector2/AlmostEqual): Returns true if we're nearly equal to the passed vector.
- [`Angle`](/api/Vector2/Angle): Returns the distance between this vector and another in degrees.
- [`Approach`](/api/Vector2/Approach): Returns a new vector whos length is closer to given target length by given amount.
- [`Clamp`](/api/Vector2/Clamp): Returns a vector each axis of which is clamped to between the 2 given vectors. Basically clamps a point to a square.
- [`ClampLength`](/api/Vector2/ClampLength): Returns a vector whose length is limited to given maximum
- [`ComponentMax`](/api/Vector2/ComponentMax): Returns a vector that has the maximum values on each axis between this vector and given vector.
- [`ComponentMin`](/api/Vector2/ComponentMin): Returns a vector that has the minimum values on each axis between this vector and given vector.
- [`CubicBezier`](/api/Vector2/CubicBezier): Calculates position of a point on a cubic bezier curve at given fraction.
- [`Direction`](/api/Vector2/Direction): Calculates the normalized direction vector from one point to another in 2D space.
- [`Distance`](/api/Vector2/Distance): Returns distance between the 2 given vectors.
- [`DistanceBetween`](/api/Vector2/DistanceBetween): Returns distance between the 2 given vectors.
- [`DistanceBetweenSquared`](/api/Vector2/DistanceBetweenSquared): Returns squared distance between the 2 given vectors. This is faster than [DistanceBetween](/api/Vector2/DistanceBetween), and can be used for things like comparing distances, as long as only squared values are used.
- [`DistanceSquared`](/api/Vector2/DistanceSquared): Returns squared distance between the 2 given vectors. This is faster than [DistanceBetween](/api/Vector2/DistanceBetween), and can be used for things like comparing distances, as long as only squared values are used.
- [`Dot`](/api/Vector2/Dot): Returns the scalar/dot product between the 2 given vectors.
- [`FromDegrees`](/api/Vector2/FromDegrees): Returns a point on a circle at given rotation from X axis, counter clockwise.
- [`FromRadians`](/api/Vector2/FromRadians): Returns a point on a circle at given rotation from X axis, counter clockwise.
- [`GetAngle`](/api/Vector2/GetAngle): Returns the distance between two direction vectors in degrees.
- [`IsNearlyZero`](/api/Vector2/IsNearlyZero): Returns true if value on every axis is less than tolerance away from zero
- [`Lerp`](/api/Vector2/Lerp): Linearly interpolate from point a to point b.
- [`LerpTo`](/api/Vector2/LerpTo): Linearly interpolate from this vector to given vector.
- [`Max`](/api/Vector2/Max): Returns a vector that has the maximum values on each axis between the 2 given vectors.
- [`Min`](/api/Vector2/Min): Returns a vector that has the minimum values on each axis between the 2 given vectors.
- [`Parse`](/api/Vector2/Parse): Given a string, try to convert this into a Vector2. Example formatting is "x,y", "[x,y]", "x y", etc.
- [`Reflect`](/api/Vector2/Reflect): Returns a reflected vector based on incoming direction and plane normal. Like a ray reflecting off of a mirror.
- [`RotateAround`](/api/Vector2/RotateAround): Rotate this vector around given point by given angle in degrees and return the result as a new vector.
- [`SmoothDamp`](/api/Vector2/SmoothDamp): Smoothly move towards the target vector
- [`SnapToGrid`](/api/Vector2/SnapToGrid): Snap to grid along all 3 axes.
- [`Sort`](/api/Vector2/Sort): Sort these two vectors into min and max. This doesn't just swap the vectors, it sorts each component. So that min will come out containing the minimum x and y values.
- [`SpringDamp`](/api/Vector2/SpringDamp): Springly move towards the target vector
- [`SubtractDirection`](/api/Vector2/SubtractDirection): Given a vector like 1,1,1 and direction 1,0,0, will return 0,1,1. This is useful for velocity collision type events, where you want to cancel out velocity based on a normal. For this to work properly, direction should be a normal, but you can scale how much you want to subtract by scaling the direction. Ie, passing in a direction with a length of 0.5 will remove half the direction.
- [`TryParse`](/api/Vector2/TryParse)
- [`WithAcceleration`](/api/Vector2/WithAcceleration): Move to the target vector, by amount acceleration
- [`WithFriction`](/api/Vector2/WithFriction)
- [`WithX`](/api/Vector2/WithX): Return this vector with given X.
- [`WithY`](/api/Vector2/WithY): Return this vector with given Y.
