Vector3
Derives from ValueType
Implements IEquatable<Vector3>, IParsable<Vector3>

## Summary

A point in 3D space.

## Constructors

Vector3( float x, float y, float z, )

Initializes a vector with given components.

Vector3( float x, float y, )

Initializes a vector with given components and Z set to 0.

Vector3( Vector3 other, )

Initializes a vector3 from a given vector3, i.e. a copy.

Vector3( Vector2 other, float z, )

Initializes a vector3 from given vector2 and the given Z component.

Vector3( float all = 0, )

Initializes the vector with all components set to given value.

## Fields

A vector with X set to -1. This represents the backwards direction.

A vector with Z set to -1. This represents the downwards direction.

A vector with X set to 1. This represents the forwards direction.

A vector with Y set to 1. This represents the left hand direction.

A vector with all components set to 1.

A vector with Z set to 1. This represents the upwards direction.

A vector with all components set to 0.

## Properties

static Vector3 Random { get; }

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

Angles EulerAngles { get; set; }

The Euler angles of this direction vector.

bool IsNaN { get; }

Returns true if x, y or z are NaN

bool IsNearZeroLength { get; }

Whether length of this vector is nearly zero.

float Length { get; }

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

float LengthSquared { get; }

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.

Vector3 Normal { get; }

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

float x { get; set; }

The X component of this Vector.

float y { get; set; }

The Y component of this Vector.

float z { get; set; }

The Z component of this Vector.

## Methods

static Vector3 Cross( Vector3 a, Vector3 b, )

Returns the cross product of the 2 given vectors. If the given vectors are linearly independent, the resulting vector is perpendicular to them both, also known as a normal of a plane.

static Vector3 CubicBeizer( Vector3 source, Vector3 target, Vector3 sourceTangent, Vector3 targetTangent, float t, )

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

static float DistanceBetween( Vector3 a, Vector3 b, )

Returns distance between the 2 given vectors.

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.

static float Dot( Vector3 a, Vector3 b, )

Returns the scalar/dot product of the 2 given vectors.

static float GetAngle( Vector3 v1, Vector3 v2, )

Return the distance between the two direction vectors in degrees.

static Vector3 Lerp( Vector3 a, Vector3 b, float frac, bool clamp = true, )

Performs linear interpolation between 2 given vectors.

static Vector3 Lerp( Vector3 a, Vector3 b, Vector3 frac, bool clamp = true, )

Performs linear interpolation between 2 given vectors, with separate fraction for each vector component.

static Vector3 Max( Vector3 a, Vector3 b, )

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

static Vector3 Min( Vector3 a, Vector3 b, )

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

static Vector3 Parse( string str, IFormatProvider provider, )
Implements IParsable`1.Parse
static Vector3 Parse( string str, )

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.

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

Smoothly move towards the target vector

static void Sort( ref Vector3 min, ref 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.

static bool TryParse( string str, out Vector3 result, )
static bool TryParse( string str, IFormatProvider provider, out Vector3 result, )
Implements IParsable`1.TryParse

Given a string, try to convert this into a vector. Example input formats that work would be "1,1,1", "1;1;1", "[1 1 1]".

This handles a bunch of different separators ( ' ', ',', ';', '\n', '\r' ).

It also trims surrounding characters ('[', ']', ' ', '\n', '\r', '\t', '"').

static Angles VectorAngle( Vector3 vec, )

Converts a direction vector to an angle.

static Vector3 VectorPlaneProject( Vector3 v, Vector3 planeNormal, )

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

Returns a new vector with all values positive. -5 becomes 5, etc.

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.

bool AlmostEqual( Vector3 v, float delta = 0.0001, )

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

float Angle( Vector3 v2, )

Return the distance between the two direction vectors in degrees.

Vector3 Approach( float length, float amount, )

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

Vector3 Clamp( Vector3 otherMin, Vector3 otherMax, )

Returns a vector each axis of which is clamped to between the 2 given vectors. Basically clamps a point to an Axis Aligned Bounding Box (AABB).

Vector3 Clamp( float min, float max, )

Returns a vector each axis of which is clamped to given min and max values.

Vector3 ClampLength( float maxLength, )

Returns a vector whose length is limited to given maximum.

Vector3 ClampLength( float minLength, float maxLength, )

Returns a vector whose length is limited between given minimum and maximum.

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

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

Returns the cross product of this and the given vector. If this and the given vectors are linearly independent, the resulting vector is perpendicular to them both, also known as a normal of a plane.

float Distance( Vector3 target, )

Returns distance between this vector to given vector.

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.

float Dot( Vector3 b, )

Returns the scalar/dot product of this and the given vectors.

bool IsNearlyZero( float tolerance = 1E-45, )

Returns true if value on every axis is less than tolerance away from zero

Vector3 LerpTo( Vector3 target, float frac, bool clamp = true, )

Performs linear interpolation between this and given vectors.

Vector3 LerpTo( Vector3 target, Vector3 frac, bool clamp = true, )

Performs linear interpolation between this and given vectors, with separate fraction for each vector component.

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.

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 for similar method that also transforms rotation.

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

Snap to grid along any of the 3 axes.

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.

Vector3 WithX( float x, )

Returns this vector with given X component.

Vector3 WithY( float y, )

Returns this vector with given Y component.

Vector3 WithZ( float z, )

Returns this vector with given Z component.

void Write( BinaryWriter writer, )

Write this vector3 to a System.IO.BinaryWriter.

override bool Equals( object obj, )
Overrides ValueType.Equals
override bool Equals( Vector3 o, )
Overrides ValueType.Equals
override int GetHashCode( )
Overrides ValueType.GetHashCode
override string ToString( )
Overrides ValueType.ToString

Formats the Vector into a string "x,y,z"

## Extensions

Clientside, returns position of this 3D vector on local clients' screen in 2D coordinates based on the Sandbox.Camera.

Vector2? ToScreen( Vector2 screenSize, )

Same as SandboxGameExtensions.ToScreen, but return value is in absolute coordinates.

## Operators

float this[ int index,  ]
Vector3 +( Vector3 c1, Vector3 c2,  )
Vector3 /( Vector3 c1, float f,  )
bool ==( Vector3 left, Vector3 right,  )
bool !=( Vector3 left, Vector3 right,  )
Vector3 *( Vector3 c1, float f,  )
Vector3 *( Vector3 c1, Rotation f,  )
Vector3 *( Vector3 c1, Vector3 c2,  )
Vector3 *( float f, Vector3 c1,  )
Vector3 -( Vector3 c1, Vector3 c2,  )
Vector3 -( Vector3 value,  )
implicit Vector3 =( Color value,  )
implicit Vector3 =( float value,  )
implicit Vector3 =( Vector2 value,  )
implicit Vector3 =( Vector4 vec,  )
implicit Vector3 =( Vector3 value,  )
implicit Vector3 =( Vector3 value,  )

## Referencing Members

Vector3 = AudioMaterial.Absorption { get; set; }
virtual void WalkController.Accelerate( float, float, float, )
ModelBuilder = ModelBuilder.AddBone( string, string, )
PhysicsShape = PhysicsBody.AddMeshShape( List<Vector3>, List<int>, )
PhysicsShape = PhysicsBody.AddMeshShape( Span<Vector3>, Span<int>, )
static Vector3 = Input.AnalogMove { get; set; }
static Vector3 = Angles.AngleVector( )
void PhysicsGroup.ApplyImpulse( bool, )
bool = GizmoControls.Arrow( string, out float, float, float, float, float, float, string, )
void DebugOverlay.Axis( float, float, bool, )
Vector3 = Entity.BaseVelocity { get; set; }
BBox.BBox( float, )
Bone.Bone( string, string, )
static Trace = Trace.Box( in Vector3, in Vector3, )
static Trace = Trace.Box( in Ray, in float, )
void DebugOverlay.Box( )
void DebugOverlay.Box( float, bool, )
void DebugOverlay.Box( float, bool, )
void DebugOverlay.Box( float, bool, )
static void Breakables.Break( float, )
static Vector3[] = NavMesh.BuildPath( )
static bool = NavMesh.BuildPath( List<Vector3>, )
Capsule.Capsule( float, )
Vector3 = BBox.Center { get; }
Vector3 = Line.Center { get; }
Vector3 = Sphere.Center { get; set; }
Vector3 = Node.Center { get; }
Vector3 = NavArea.Center { get; }
void GizmoHitbox.Circle( float, float, )
void DebugOverlay.Circle( float, float, bool, )
bool = BBox.Contains( )
static void SandboxBaseExtensions.CopyBonesFrom( float, )
IEnumerable<Vector3> = BBox.Corners { get; }
static Particles = Particles.Create( string, )
static Matrix = Matrix.CreateRotationX( float, )
static Matrix = Matrix.CreateRotationY( float, )
static Matrix = Matrix.CreateRotationZ( float, )
static Matrix = Matrix.CreateScale( )
static Matrix = Matrix.CreateScale( )
static SliderJoint = PhysicsJoint.CreateSlider( float, float, )
static Matrix = Matrix.CreateWorld( )
Vector3 = Line.Delta { get; }
float = Line.Distance( )
float = Line.Distance( out Vector3, )
float = Node.Distance( )
Vector3 = Rotation.Down { get; }
Vector3 = Transform.Down { get; }
static void ToolRender.DrawBox( )
static void ToolRender.DrawLine( )
static void ToolRender.DrawLine( )
static void ToolRender.DrawWorldSpaceText( string, float, )
Vector3 = Line.End { get; }
Vector3 = NavigationPath.EndPoint { get; set; }
Vector3 = Result.EndPosition { get; set; }
Vector3 = Player.EyeLocalPosition { get; set; }
Vector3 = Player.EyePosition { get; set; }
Vector3 = ShatterGlass.FaceCenter { get; set; }
Vector3 = VoxelSurface.FaceCenter { get; set; }
static Vector3 = Noise.FbmVector( int, float, float, )
static IEnumerable<Entity> = Entity.FindInSphere( float, )
Vector3 = DamageInfo.Force { get; set; }
Vector3 = Angles.Forward { get; set; }
Vector3 = Ray.Forward { get; set; }
Vector3 = Rotation.Forward { get; }
static Rotation = Rotation.FromAxis( float, )
static DamageInfo = DamageInfo.FromBullet( float, )
static DamageInfo = DamageInfo.FromExplosion( float, )
static BBox = BBox.FromPoints( IEnumerable<Vector3>, float, )
static BBox = BBox.FromPositionAndSize( float, )
static Sound = Sound.FromWorld( To, string, )
static Sound = Sound.FromWorld( string, )
GenericEvent.GenericEvent( string, int, float, string, )
static NavArea = NavArea.GetClosestNav( ref Vector3, float, float, float, float, )
static NavArea = NavArea.GetClosestNav( float, float, float, float, )
static Vector3 = Screen.GetDirection( float, )
static Vector3 = Screen.GetDirection( float, )
static Vector3 = Screen.GetDirection( float, )
float = Plane.GetDistance( )
static float = Gizmo.GetMouseDistance( )
static float = Gizmo.GetMouseDistanceDelta( )
static Vector3? = NavMesh.GetPointWithinRadius( float, float, )
static Vector3? = NavMesh.GetPointWithinRadius( float, float, )
Vector3 = PhysicsWorld.Gravity { get; set; }
Vector3 = PhysicsSettings.Gravity { get; set; }
Vector3 = Result.HitNormal { get; set; }
Vector3 = Result.HitPosition { get; set; }
Vector3 = Player.InputDirection { get; protected set; }
bool = Plane.IsInFront( )
bool = Frustum.IsInside( )
Vector3 = Rotation.Left { get; }
Vector3 = Transform.Left { get; }
Line.Line( float, )
void DebugOverlay.Line( float, bool, )
void DebugOverlay.Line( float, bool, )
void GizmoDraw.LineCylinder( float, float, int, )
virtual Vector3 = Entity.LocalPosition { get; set; }
override Vector3 = ModelEntity.LocalPosition { get; set; }
virtual Vector3 = Entity.LocalVelocity { get; set; }
static Rotation = Rotation.LookAt( )
static Rotation = Rotation.LookAt( )
void FlyingController.Move( int, )
MoveHelper.MoveHelper( string[], )
Vector3 = Triangle.Normal { get; }
Vector3 = Node.Normal { get; }
Vector3 = VertexDetail.Normal { get; set; }
Vector3 = NavArea.Normal { get; }
Vector3 = SkyboxAccessor.Offset { get; set; }
Vector3 = ModelBreakPiece.Offset { get; set; }
virtual void ModelEntity.OnAnimEventFootstep( int, float, )
override void Player.OnAnimEventFootstep( int, float, )
virtual void ModelEntity.OnAnimEventGeneric( string, int, float, string, )
protected virtual void AnimatedEntity.OnAnimFootstep( bool, )
static BBox = BBox.op_Addition( BBox, )
static Color = Color.op_Implicit( )
Vector3 = Plane.Origin { get; }
static Vector3 = Selection.PivotPosition { get; set; }
static void Decal.Place( To, int, )
static void Decal.Place( int, )
static void Decal.Place( int, )
static void Decal.Place( )
static void Decal.Place( )
Plane.Plane( double, )
void GizmoDraw.Plane( )
abstract void AnimGraphDirectPlayback.Play( string, float, float, )
Vector3 = PhysicsGroup.Pos { get; }
Vector3 = Ray.Position { get; set; }
static Vector3 = Camera.Position { get; set; }
abstract Vector3 = IEntity.Position { get; set; }
Vector3 = PhysicsBody.Position { get; set; }
Vector3 = SceneCamera.Position { get; set; }
Vector3 = SceneObject.Position { get; set; }
Vector3 = MusicPlayer.Position { get; set; }
bool = GizmoControls.Position( string, out Vector3, Rotation?, float, )
Vector3 = Bone.Position { get; init; }
Vector3 = SkyboxAccessor.Position { get; set; }
Vector3 = SoundEvent.Position { get; set; }
abstract Vector3 = EntityObject.Position { get; set; }
Vector3 = VertexDetail.Position { get; set; }
virtual Vector3 = Entity.Position { get; set; }
override Vector3 = ModelEntity.Position { get; set; }
Vector3 = DamageInfo.Position { get; set; }
Vector3 = MapNode.Position { get; set; }
Vector3 = BasePathNode.Position { get; set; }
abstract Vector3 = ISoundscapeEntity.Position { get; }
Vector3 = PawnController.Position { get; set; }
Vector3 = WorldPanel.Position { get; set; }
Vector3 = Ray.Project( float, )
Ray.Ray( )
Vector3 = Rotation.Right { get; }
Vector3 = Transform.Right { get; }
Rotation.Rotation( float, )
abstract Vector3 = EntityObject.Scale { get; set; }
Vector3 = MapNode.Scale { get; set; }
static ScenePanel = SceneConstructor.ScenePanel( float, string, )
static IDisposable = Gizmo.Scope( string, )
static IDisposable = Gizmo.Scope( string, float, )
protected virtual float = NavigationPath.ScoreFor( in Connection, )
bool = Material.Set( string, )
void AnimatedEntity.SetAnimLookAt( string, )
void SceneModel.SetAnimParameter( string, )
virtual void WalkController.SetBBox( )
void Mesh.SetBounds( )
void Particles.SetEntity( int, bool, )
void Particles.SetEntityAttachment( int, string, )
void Particles.SetForward( int, )
void SceneParticles.SetNamedValue( string, )
void Particles.SetPosition( int, )
Vector3 = BBox.Size { get; }
Vector3 = SceneCullingBox.Size { get; set; }
void GizmoDraw.SolidCapsule( float, int, int, )
void GizmoDraw.SolidCircle( float, float, float, int, )
void GizmoDraw.SolidCone( float, int?, )
void GizmoDraw.SolidCylinder( float, int, )
void GizmoDraw.SolidRing( float, float, float, float, int, )
void GizmoDraw.SolidSphere( float, int, int, )
SoundEvent.SoundEvent( string, string, )
Sphere.Sphere( float, )
void DebugOverlay.Sphere( float, float, bool, )
void GizmoDraw.Sprite( float, string, )
void GizmoDraw.Sprite( float, )
void GizmoDraw.Sprite( bool, )
float = Line.SqrDistance( )
Vector3 = Line.Start { get; }
Vector3 = Result.StartPosition { get; set; }
Vector3 = BasePathNode.TangentIn { get; set; }
Vector3 = BasePathNode.TangentOut { get; set; }
static bool = Trace.TestPoint( string, float, )
virtual bool = SoundscapeBoxEntity.TestPosition( )
abstract bool = ISoundscapeEntity.TestPosition( )
void DebugOverlay.Text( string, int, float, float, )
void DebugOverlay.Text( string, float, float, )
void DebugOverlay.Text( string, float, float, )
Vector3? = Plane.Trace( Ray, bool, double, )
override TraceResult = WalkController.TraceBBox( float, )
virtual IEnumerable<TraceResult> = BaseWeapon.TraceBullet( float, )
Transform.Transform( float, )
void GlassShard.TryGenerateShardModel( bool, bool, )
virtual bool = KeyframeEntity.TryLocalKeyframeTo( float, )
Vector3 = Rotation.Up { get; }
Vector3 = Transform.Up { get; }
void PlanarReflection.Update( float, )
void PhysicsShape.UpdateMesh( List<Vector3>, List<int>, )
void PhysicsShape.UpdateMesh( Span<Vector3>, Span<int>, )
Vector3 = Vector3Property.Value { get; set; }
Vector3 = GenericEvent.Vector { get; set; }
Vector3 = AsAccessor.Vector3 { get; set; }
static Vector3 = SandboxSystemExtensions.VectorInCube( Random, float, )
static Vector3 = SandboxSystemExtensions.VectorInSphere( Random, float, )
abstract Vector3 = IEntity.Velocity { get; set; }
Vector3 = PhysicsBody.Velocity { get; set; }
Vector3 = VrHand.Velocity { get; }
virtual Vector3 = Entity.Velocity { get; set; }
override Vector3 = ModelEntity.Velocity { get; set; }
Vector3 = VrHand.Velocity { get; set; }
Vector3 = PawnController.Velocity { get; set; }
Vector3 = Result.VertexInfluence { get; set; }
List<Vector3> = Node.Vertices { get; }
Vector3 = ScenePortal.ViewPosition { get; set; }
void CitizenAnimationHelper.WithLookAt( float, float, float, )
abstract Vector3 = IBasePathNode.WorldPosition { get; }
virtual Vector3 = BasePathNode.WorldPosition { get; }
abstract Vector3 = IBasePathNode.WorldTangentIn { get; }
virtual Vector3 = BasePathNode.WorldTangentIn { get; }
abstract Vector3 = IBasePathNode.WorldTangentOut { get; }
virtual Vector3 = BasePathNode.WorldTangentOut { get; }
static void SandboxSystemExtensions.Write( BinaryWriter, )