Table of Contents

Class Vector

Namespace
CounterStrikeSharp.API.Modules.Utils
Assembly
CounterStrikeSharp.API.dll

A Vector object represents a line with a direction and length. Each vector contains three co-ordinates:

  • X+forward/-backward
  • Y+left/-right
  • Z+up/-down
public class Vector : NativeObject
Inheritance
Vector
Inherited Members

Constructors

Vector(nint)

public Vector(nint pointer)

Parameters

pointer nint

Vector(float?, float?, float?)

public Vector(float? x = null, float? y = null, float? z = null)

Parameters

x float?
y float?
z float?

Properties

this[int]

public float this[int i] { get; set; }

Parameters

i int

Property Value

float

X

public ref float X { get; }

Property Value

float

Y

public ref float Y { get; }

Property Value

float

Z

public ref float Z { get; }

Property Value

float

Methods

Add(Vector)

Adds values of argument vector to the original vector. Does not create a new vector object, skipping object construction.

public void Add(Vector vector)

Parameters

vector Vector

Angle()

Returns an angle that represents the normal of the vector.

public Angle Angle()

Returns

Angle

Angle(Vector)

Returns the angle of the vector, but allows the use of a different 'up' direction.

public Angle Angle(Vector up)

Parameters

up Vector

Direction for up

Returns

Angle

IsZero()

Returns whether all fields on the Vector are 0.

public bool IsZero()

Returns

bool

Length()

Returns the Euclidean length of the vector: √x² + y² + z²

public float Length()

Returns

float

Euclidean length of vector

Length2D()

Returns length of Vector excluding Z axis.

public float Length2D()

Returns

float

2D Length

Length2DSqr()

Returns the squared length of the vectors x and y value, x² + y². Faster than Length2D()

public float Length2DSqr()

Returns

float

LengthSqr()

Returns the squared length of the vector, x² + y² + z². Faster than Length()

public float LengthSqr()

Returns

float

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

With(float?, float?, float?)

Returns a copy of the vector with values replaced.

public Vector With(float? x = null, float? y = null, float? z = null)

Parameters

x float?

X value to replace with

y float?

Y value to replace with

z float?

Z value to replace with

Returns

Vector

Copy of vector

Operators

operator +(Vector, Vector)

public static Vector operator +(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

operator /(Vector, float)

public static Vector operator /(Vector a, float b)

Parameters

a Vector
b float

Returns

Vector

operator *(Vector, float)

public static Vector operator *(Vector a, float b)

Parameters

a Vector
b float

Returns

Vector

operator -(Vector, Vector)

public static Vector operator -(Vector a, Vector b)

Parameters

a Vector
b Vector

Returns

Vector

operator -(Vector)

public static Vector operator -(Vector a)

Parameters

a Vector

Returns

Vector