Vector2class
A 2-dimensional vector. Typically represents a position, size, or direction in 2D space.
Constructors6
Showing 6 constructors
No results match this filter.
Methods49
Showing 49 methods
public Vector2 AddClamped(Vector2 toAdd, float maxLength)
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.
| Parameter | Type | Description |
|---|---|---|
| toAdd | Vector2 | — |
| maxLength | float | — |
public bool AlmostEqual(Vector2 v, float delta = 0.0001)
Returns true if we're nearly equal to the passed vector.
| Parameter | Type | Description |
|---|---|---|
| v | Vector2 | The value to compare with |
| delta = 0.0001 | float | The max difference between component values |
boolTrue if nearly equalpublic float Angle(Vector2 other)
Returns the distance between this vector and another in degrees.
| Parameter | Type | Description |
|---|---|---|
| other | Vector2 | — |
float—public Vector2 Approach(float length, float amount)
Returns a new vector whos length is closer to given target length by given amount.
| Parameter | Type | Description |
|---|---|---|
| length | float | — |
| amount | float | — |
public Vector2 ComponentMax(Vector2 other)
Returns a vector that has the maximum values on each axis between this vector and given vector.
| Parameter | Type | Description |
|---|---|---|
| other | Vector2 | — |
public Vector2 ComponentMin(Vector2 other)
Returns a vector that has the minimum values on each axis between this vector and given vector.
| Parameter | Type | Description |
|---|---|---|
| other | Vector2 | — |
public static Vector2 CubicBezier(Vector2 source, Vector2 target, Vector2 sourceTangent, Vector2 targetTangent, float t)
Calculates position of a point on a cubic bezier curve at given fraction.
| Parameter | Type | Description |
|---|---|---|
| source | Vector2 | Point A of the curve. |
| target | Vector2 | Point B of the curve. |
| sourceTangent | Vector2 | Tangent for the Point A. |
| targetTangent | Vector2 | Tangent for the Point B. |
| t | float | How far along the path to get a point on. Range is 0 to 1, inclusive. |
public static Vector2 Direction(Vector2 from, Vector2 to)
Calculates the normalized direction vector from one point to another in 2D space.
| Parameter | Type | Description |
|---|---|---|
| from | Vector2 | — |
| to | Vector2 | — |
public static float DistanceBetween(Vector2 a, Vector2 b)
Returns distance between the 2 given vectors.
| Parameter | Type | Description |
|---|---|---|
| a | Vector2 | — |
| b | Vector2 | — |
float—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.
| Parameter | Type | Description |
|---|---|---|
| a | Vector2 | — |
| b | Vector2 | — |
float—public static Vector2 FromDegrees(float degrees)
Returns a point on a circle at given rotation from X axis, counter clockwise.
| Parameter | Type | Description |
|---|---|---|
| degrees | float | — |
public static Vector2 FromRadians(float radians)
Returns a point on a circle at given rotation from X axis, counter clockwise.
| Parameter | Type | Description |
|---|---|---|
| radians | float | — |
public static float GetAngle(Vector2 v1, Vector2 v2)
Returns the distance between two direction vectors in degrees.
| Parameter | Type | Description |
|---|---|---|
| v1 | Vector2 | — |
| v2 | Vector2 | — |
float—public bool IsNearlyZero(float tolerance = 0.0001)
Returns true if value on every axis is less than tolerance away from zero
| Parameter | Type | Description |
|---|---|---|
| tolerance = 0.0001 | float | — |
bool—public static Vector2 Max(Vector2 a, Vector2 b)
Returns a vector that has the maximum values on each axis between the 2 given vectors.
| Parameter | Type | Description |
|---|---|---|
| a | Vector2 | — |
| b | Vector2 | — |
public static Vector2 Min(Vector2 a, Vector2 b)
Returns a vector that has the minimum values on each axis between the 2 given vectors.
| Parameter | Type | Description |
|---|---|---|
| a | Vector2 | — |
| b | Vector2 | — |
public static Vector2 Reflect(Vector2 direction, Vector2 normal)
Returns a reflected vector based on incoming direction and plane normal. Like a ray reflecting off of a mirror.
| Parameter | Type | Description |
|---|---|---|
| direction | Vector2 | — |
| normal | Vector2 | — |
public Vector2 RotateAround(Vector2 center, float angleDegrees)
Rotate this vector around given point by given angle in degrees and return the result as a new vector.
| Parameter | Type | Description |
|---|---|---|
| center | Vector2 | — |
| angleDegrees | float | — |
public static Vector2 SmoothDamp(Vector2 current, Vector2 target, Vector2 velocity, float smoothTime, float deltaTime)
Smoothly move towards the target vector
| Parameter | Type | Description |
|---|---|---|
| current | Vector2 | — |
| target | Vector2 | — |
| velocity | Vector2 | — |
| smoothTime | float | — |
| deltaTime | float | — |
public Vector2 SnapToGrid(float gridSize, bool sx = True, bool sy = True)
Snap to grid along all 3 axes.
| Parameter | Type | Description |
|---|---|---|
| gridSize | float | — |
| sx = True | bool | — |
| sy = True | bool | — |
public static void Sort(Vector2 min, Vector2 max)
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.
| Parameter | Type | Description |
|---|---|---|
| min | Vector2 | — |
| max | Vector2 | — |
void—public Vector2 SubtractDirection(Vector2 direction, float strength = 1)
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.
| Parameter | Type | Description |
|---|---|---|
| direction | Vector2 | — |
| strength = 1 | float | — |
public Vector2 WithAcceleration(Vector2 target, float accelerate)
Move to the target vector, by amount acceleration
| Parameter | Type | Description |
|---|---|---|
| target | Vector2 | — |
| accelerate | float | — |
public Vector2 WithFriction(float frictionAmount, float stopSpeed = 140)
| Parameter | Type | Description |
|---|---|---|
| frictionAmount | float | — |
| stopSpeed = 140 | float | — |
public Vector2 WithX(float x)
Return this vector with given X.
| Parameter | Type | Description |
|---|---|---|
| x | float | — |
No results match this filter.
Properties19
Showing 19 properties
public float Vector2.Degrees { get; set; }
Return the angle of this vector in degrees, always between 0 and 360
float—public static Vector2 Vector2.Down { get; set; }
Returns a 2D vector with Y set to 1. This typically represents down in 2D space.
public Vector2 Vector2.Inverse { get; set; }
Returns the inverse of this vector, which is useful for scaling vectors
public bool Vector2.IsInfinity { get; set; }
Returns true if x, y, or z are infinity
bool—public bool Vector2.IsNaN { get; set; }
Returns true if x, y, or z are NaN
bool—public bool Vector2.IsNearZeroLength { get; set; }
Returns true if the squared length is less than 1e-8 (which is really near zero)
bool—public static Vector2 Vector2.Left { get; set; }
Returns a 2D vector with X set to -1. This typically represents the left hand direction in 2D space.
public float Vector2.LengthSquared { get; set; }
This is faster than Length, so is better to use in certain circumstances
float—public Vector2 Vector2.Perpendicular { get; set; }
Returns a vector that runs perpendicular to this one
public static Vector2 Vector2.Random { get; set; }
Uniformly samples a 2D position from all points with distance at most 1 from the origin.
public static Vector2 Vector2.Right { get; set; }
Returns a 2D vector with X set to 1. This typically represents the right hand direction in 2D space.
public static Vector2 Vector2.Up { get; set; }
Returns a 2D vector with Y set to -1. This typically represents up in 2D space.
public float Vector2.x { get; set; }
X component of this vector.
float—public float Vector2.y { get; set; }
Y component of this vector.
float—No results match this filter.