s&box docs

public sealed struct Vector3

A 3-dimentional vector. Typically represents a position, size, or direction in 3D space.

Broader workflow and conceptual references connected to this API.

Constructors

Showing 6 constructors

Methods

Showing 56 methods

public Vector3 AddClamped(Vector3 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(Vector3 v, float delta = 0.0001)

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

Parameters

  • v: The value to compare with
  • delta: The max difference between component values Default: 0.0001

Returns

True if nearly equal

public float Angle(Vector3 other)

Return the distance between the two direction vectors in degrees.

public Vector3 Approach(float length, float amount)

Returns a new vector whose length is closer to given target length by given amount.

Parameters

  • length: Target length.
  • amount: How much to subtract or add.

public static Vector3 CatmullRomSpline(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)

Calculates a point on a Catmull-Rom spline given four control points and a parameter t.

public Vector3 ComponentMax(Vector3 other)

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

public Vector3 ComponentMin(Vector3 other)

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

public static Vector3 CubicBezier(Vector3 source, Vector3 target, Vector3 sourceTangent, Vector3 targetTangent, float t)

Calculates position of a point on a cubic beizer curve at given fraction.

Parameters

  • source: Point A of the curve in world space.
  • target: Point B of the curve in world space.
  • sourceTangent: Tangent for the Point A in world space.
  • targetTangent: Tangent for the Point B in world space.
  • 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 Vector3 Direction(Vector3 from, Vector3 to)

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

public float Distance(Vector3 target)

Returns distance between this vector to given vector.

public static float DistanceBetween(Vector3 a, Vector3 b)

Returns distance between the 2 given vectors.

public static float DistanceBetweenSquared(Vector3 a, Vector3 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(Vector3 target)

Returns squared distance between this vector to given vector. 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 GetAngle(Vector3 v1, Vector3 v2)

Return the distance between the two direction vectors in degrees.

public static float InverseLerp(Vector3 pos, Vector3 a, Vector3 b, bool clamp = True)

Given a position, and two other positions, calculate the inverse lerp position between those

Parameters

  • clamp: Default: True

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 Vector3 Max(Vector3 a, Vector3 b)

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

public static Vector3 Min(Vector3 a, Vector3 b)

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

public Vector3 ProjectOnNormal(Vector3 normal)

Projects this vector onto another vector. Basically extends the given normal/unit vector to be as long as necessary to make a right triangle (a triangle which has a 90 degree corner) between (0,0,0), this vector and the projected vector.

Returns

The projected vector.

public static Vector3 Reflect(Vector3 direction, Vector3 normal)

Returns a reflected vector based on incoming direction and plane normal. Like a ray reflecting off of a mirror.

public Vector3 RotateAround(Vector3 center, Rotation rot)

Rotate this vector around given point by given rotation and return the result as a new vector. See `Transform.RotateAround(Vector3@,Rotation@)` for similar method that also transforms rotation.

Parameters

  • center: Point to rotate around.
  • rot: How much to rotate by. `Rotation.FromAxis(Vector3,System.Single)` can be useful.

Returns

The rotated vector.

public static Vector3 Slerp(Vector3 a, Vector3 b, float frac, bool clamp = True)

Performs spherical linear interpolation (Slerp) between two vectors.

Parameters

  • a: Starting vector (A).
  • b: Target vector (B).
  • frac: Interpolation fraction: 0 returns A, 1 returns B, and values in between provide intermediate results along the spherical path.
  • clamp: If true, clamps the fraction between 0 and 1. Default: True

Returns

Interpolated vector along the spherical path.

public Vector3 SlerpTo(Vector3 target, float frac, bool clamp = True)

Performs spherical linear interpolation (Slerp) between this vector and a target vector.

Parameters

  • target: The target vector to interpolate towards.
  • frac: Interpolation fraction: 0 returns this vector, 1 returns the target vector, and values in between provide intermediate results along the spherical path.
  • clamp: If true, clamps the fraction between 0 and 1. Default: True

Returns

Interpolated vector along the spherical path.

public static Vector3 SmoothDamp(Vector3 current, Vector3 target, Vector3 velocity, float smoothTime, float deltaTime)

Smoothly move towards the target vector

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

Snap to grid along any of the 3 axes.

Parameters

  • sx: Default: True
  • sy: Default: True
  • sz: Default: True

public static void Sort(Vector3 min, Vector3 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, y and z values.

public Vector3 SubtractDirection(Vector3 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 static Vector3 TcbSpline(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float tension, float continuity, float bias, float u)

Calculates an interpolated point using the Kochanek-Bartels spline (TCB spline).

Parameters

  • tension: Tension parameter which affects the sharpness at the control point. Positive values make the curve tighter, negative values make it rounder.
  • continuity: Continuity parameter which affects the continuity between segments. Positive values create smoother transitions, negative values can create corners.
  • bias: Bias parameter which affects the direction of the curve as it passes through the control point. Positive values bias the curve towards the next point, negative values towards the previous.
  • u: The interpolation parameter between 0 and 1, where 0 is the start of the segment and 1 is the end.

Returns

The interpolated point on the curve.

public static Angles VectorAngle(Vector3 vec)

Converts a direction vector to an angle.

public static Vector3 VectorPlaneProject(Vector3 v, Vector3 planeNormal)

Projects given vector on a plane defined by `planeNormal`.

Parameters

  • v: The vector to project.
  • planeNormal: Normal of a plane to project onto.

Returns

The projected vector.

public Vector3 WithAcceleration(Vector3 target, float acceleration)

Move to the target vector, by amount acceleration

public Vector3 WithFriction(float frictionAmount, float stopSpeed = 140)

Apply an amount of friction to the current velocity.

Parameters

  • stopSpeed: Default: 140

public Vector3 WithX(float x)

Returns this vector with given X component.

Parameters

  • x: The override for X component.

Returns

The new vector.

public Vector3 WithY(float y)

Returns this vector with given Y component.

Parameters

  • y: The override for Y component.

Returns

The new vector.

public Vector3 WithZ(float z)

Returns this vector with given Z component.

Parameters

  • z: The override for Z component.

Returns

The new vector.

Properties

Showing 13 properties

public Angles Vector3.EulerAngles { get; set; }

The Euler angles of this direction vector.

public Vector3 Vector3.Inverse { get; set; }

Returns the inverse of this vector, which is useful for scaling vectors.

public bool Vector3.IsInfinity { get; set; }

Returns true if x, y or z are infinity

public bool Vector3.IsNaN { get; set; }

Returns true if x, y or z are NaN

public bool Vector3.IsNearZeroLength { get; set; }

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

public float Vector3.Length { get; set; }

Length (or magnitude) of the vector (Distance from 0,0,0).

public float Vector3.LengthSquared { get; set; }

Squared length of the vector. This is faster than Length, and can be used for things like comparing distances, as long as only squared values are used.

public Vector3 Vector3.Normal { get; set; }

Returns a unit version of this vector. A unit vector has length of 1.

public static Vector3 Vector3.Random { get; set; }

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

public float Vector3.x { get; set; }

The X component of this vector.

public float Vector3.y { get; set; }

The Y component of this vector.

public float Vector3.z { get; set; }

The Z component of this vector.

Metadata

FieldValue
Namespaceglobal
Typeclass
AssemblySandbox.System
Doc IDT:Vector3

On this page

Constructorspublic Vector3(System.Numerics.Vector3 v)public Vector3(System.Single x, System.Single y, System.Single z)public Vector3(System.Single x, System.Single y)public Vector3(System.Single all = 0)public Vector3(Vector2 other, System.Single z)public Vector3(Vector3 other)Methodspublic Vector3 Abs()public static Vector3 Abs(Vector3 value)public Vector3 AddClamped(Vector3 toAdd, System.Single maxLength)public System.Boolean AlmostEqual(Vector3 v, System.Single delta = 0.0001)public System.Single Angle(Vector3 other)public Vector3 Approach(System.Single length, System.Single amount)public static Vector3 CatmullRomSpline(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, System.Single t)public Vector3 Clamp(System.Single min, System.Single max)public Vector3 Clamp(Vector3 otherMin, Vector3 otherMax)public static Vector3 Clamp(Vector3 value, Vector3 min, Vector3 max)public Vector3 ClampLength(System.Single minLength, System.Single maxLength)public Vector3 ClampLength(System.Single maxLength)public Vector3 ComponentMax(Vector3 other)public Vector3 ComponentMin(Vector3 other)public static Vector3 Cross(Vector3 a, Vector3 b)public Vector3 Cross(Vector3 b)public static Vector3 CubicBezier(Vector3 source, Vector3 target, Vector3 sourceTangent, Vector3 targetTangent, System.Single t)public static Vector3 Direction(Vector3 from, Vector3 to)public System.Single Distance(Vector3 target)public static System.Single DistanceBetween(Vector3 a, Vector3 b)public static System.Single DistanceBetweenSquared(Vector3 a, Vector3 b)public System.Single DistanceSquared(Vector3 target)public static System.Single Dot(Vector3 a, Vector3 b)public System.Single Dot(Vector3 b)public static System.Single GetAngle(Vector3 v1, Vector3 v2)public static System.Single InverseLerp(Vector3 pos, Vector3 a, Vector3 b, System.Boolean clamp = True)public System.Boolean IsNearlyZero(System.Single tolerance = 0.0001)public static Vector3 Lerp(Vector3 a, Vector3 b, System.Single frac, System.Boolean clamp = True)public static Vector3 Lerp(Vector3 a, Vector3 b, Vector3 frac, System.Boolean clamp = True)public Vector3 LerpTo(Vector3 target, System.Single frac, System.Boolean clamp = True)public Vector3 LerpTo(Vector3 target, Vector3 frac, System.Boolean clamp = True)public static Vector3 Max(Vector3 a, Vector3 b)public static Vector3 Min(Vector3 a, Vector3 b)public static override Vector3 Parse(System.String str, System.IFormatProvider provider)public static Vector3 Parse(System.String str)public Vector3 ProjectOnNormal(Vector3 normal)public static Vector3 Reflect(Vector3 direction, Vector3 normal)public Vector3 RotateAround(Vector3 center, Rotation rot)public static Vector3 Slerp(Vector3 a, Vector3 b, System.Single frac, System.Boolean clamp = True)public Vector3 SlerpTo(Vector3 target, System.Single frac, System.Boolean clamp = True)public static Vector3 SmoothDamp(Vector3 current, Vector3 target, Vector3 velocity, System.Single smoothTime, System.Single deltaTime)public Vector3 SnapToGrid(System.Single gridSize, System.Boolean sx = True, System.Boolean sy = True, System.Boolean sz = True)public static System.Void Sort(Vector3 min, Vector3 max)public static Vector3 SpringDamp(Vector3 current, Vector3 target, Vector3 velocity, System.Single smoothTime, System.Single deltaTime, System.Single frequency = 2, System.Single damping = 0.5)public static Vector3 SpringDamp(Vector3 current, Vector3 target, Vector3 velocity, System.Single deltaTime, System.Single frequency = 2, System.Single damping = 0.5)public Vector3 SubtractDirection(Vector3 direction, System.Single strength = 1)public static Vector3 TcbSpline(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, System.Single tension, System.Single continuity, System.Single bias, System.Single u)public static override System.Boolean TryParse(System.String str, System.IFormatProvider provider, Vector3 result)public static System.Boolean TryParse(System.String str, Vector3 result)public static Angles VectorAngle(Vector3 vec)public static Vector3 VectorPlaneProject(Vector3 v, Vector3 planeNormal)public Vector3 WithAcceleration(Vector3 target, System.Single acceleration)public Vector3 WithFriction(System.Single frictionAmount, System.Single stopSpeed = 140)public Vector3 WithX(System.Single x)public Vector3 WithY(System.Single y)public Vector3 WithZ(System.Single z)Propertiespublic Angles Vector3.EulerAngles { get; set; }public Vector3 Vector3.Inverse { get; set; }public System.Boolean Vector3.IsInfinity { get; set; }public System.Boolean Vector3.IsNaN { get; set; }public System.Boolean Vector3.IsNearZeroLength { get; set; }public System.Single Vector3.Item { get; set; }public System.Single Vector3.Length { get; set; }public System.Single Vector3.LengthSquared { get; set; }public Vector3 Vector3.Normal { get; set; }public static Vector3 Vector3.Random { get; set; }public System.Single Vector3.x { get; set; }public System.Single Vector3.y { get; set; }public System.Single Vector3.z { get; set; }Metadata