public sealed struct Vector3
A 3-dimentional vector. Typically represents a position, size, or direction in 3D space.
Related Guides
Broader workflow and conceptual references connected to this API.
If you want a specific file/asset type to have a custom Thumbnail/Inspector Preview, you can simply create an AssetPreview. An AssetPreview initializes a SceneWorld and SceneCamera, rendering the Camera to the Preview output, so all you need to do is populate it and/or position the Camera to your liking.
By default, async tasks in s&box run on the main thread. They operate a lot like coroutines, making them the perfect replacement.
Just like Subgraphs, you can also create your own custom Nodes with C# (and shader code) to be used in Shader Graphs.
Sometimes you know what you're looking for, but you don't know where it is.
Some Input methods are specific to Controllers/Gamepads, and are useful to know for making sure your player experience caters to those who don't play on a Keyboard + Mouse.
The particle system is designed to let you control the particles via your own code based components, if you choose to.
Constructors
Showing 6 constructors
No results match this filter.
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 withdelta: 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: Truesy: Default: Truesz: 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 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.
No results match this filter.
Properties
Showing 13 properties
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.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.
No results match this filter.
Metadata
| Field | Value |
|---|---|
| Namespace | global |
| Type | class |
| Assembly | Sandbox.System |
| Doc ID | T:Vector3 |