public sealed struct Vector2
A 2-dimensional vector. Typically represents a position, size, or direction in 2D space.
Related Guides
Broader workflow and conceptual references connected to this API.
Sometimes you know what you're looking for, but you don't know where it is.
Editor Apps are apps that run in the editor. They generally have their own window. They're sometimes used to edit specific types of asset.
Each camera has a HudPainter that can be used to draw onto the HUD. You do this every frame, in any Update function.
VirtualGrid is a Panel that allows you to create a grid of items virtually. What this means is that if you have 1 million items, it won't render them and try to lay them all out at the same time. It'll just pick the few that are visible and create them. When you scroll down, it'll delete the ones it can no longer see and create the new visible ones.
A Vector is just a set of numbers that describe a position or a direction in space.
Constructors
Showing 6 constructors
No results match this filter.
Methods
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.
public bool AlmostEqual(Vector2 v, float delta = 0.0001)
Returns true if we're nearly equal to the passed vector.
Parameters
v: The value to compare withdelta: The max difference between component values Default: 0.0001
Returns
True if nearly equal
public float Angle(Vector2 other)
Returns the distance between this vector and another in degrees.
public Vector2 Approach(float length, float amount)
Returns a new vector whos length is closer to given target length by given amount.
public Vector2 ComponentMax(Vector2 other)
Returns a vector that has the maximum values on each axis between this vector and given vector.
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 CubicBezier(Vector2 source, Vector2 target, Vector2 sourceTangent, Vector2 targetTangent, float t)
Calculates position of a point on a cubic bezier curve at given fraction.
Parameters
source: Point A of the curve.target: Point B of the curve.sourceTangent: Tangent for the Point A.targetTangent: Tangent for the Point B.t: How far along the path to get a point on. Range is 0 to 1, inclusive.
Returns
The point on the curve
public static Vector2 Direction(Vector2 from, Vector2 to)
Calculates the normalized direction vector from one point to another in 2D space.
public static float DistanceBetween(Vector2 a, Vector2 b)
Returns distance between the 2 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 Vector2 FromDegrees(float degrees)
Returns a point on a circle at given rotation from X axis, counter clockwise.
public static Vector2 FromRadians(float radians)
Returns a point on a circle at given rotation from X axis, counter clockwise.
public static float GetAngle(Vector2 v1, Vector2 v2)
Returns the distance between two direction vectors in degrees.
public bool IsNearlyZero(float tolerance = 0.0001)
Returns true if value on every axis is less than tolerance away from zero
Parameters
tolerance: Default: 0.0001
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 Min(Vector2 a, Vector2 b)
Returns a vector that has the minimum values on each axis between the 2 given vectors.
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.
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.
public static Vector2 SmoothDamp(Vector2 current, Vector2 target, Vector2 velocity, float smoothTime, float deltaTime)
Smoothly move towards the target vector
public Vector2 SnapToGrid(float gridSize, bool sx = True, bool sy = True)
Snap to grid along all 3 axes.
Parameters
sx: Default: Truesy: Default: True
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.
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.
Parameters
strength: Default: 1
public Vector2 WithAcceleration(Vector2 target, float accelerate)
Move to the target vector, by amount acceleration
public Vector2 WithFriction(float frictionAmount, float stopSpeed = 140)
Parameters
stopSpeed: Default: 140
public Vector2 WithX(float x)
Return this vector with given X.
public Vector2 WithY(float y)
Return this vector with given Y.
No results match this filter.
Properties
Showing 19 properties
public float Vector2.Degrees { get; set; }
Return the angle of this vector in degrees, always between 0 and 360
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
public bool Vector2.IsNaN { get; set; }
Returns true if x, y, or z are NaN
public bool Vector2.IsNearZeroLength { get; set; }
Returns true if the squared length is less than 1e-8 (which is really near zero)
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
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.
public float Vector2.y { get; set; }
Y component of this vector.
No results match this filter.
Metadata
| Field | Value |
|---|---|
| Namespace | global |
| Type | class |
| Assembly | Sandbox.System |
| Doc ID | T:Vector2 |