# vector

## Example available!

{% content-ref url="../../useful-information/script-examples/vector" %}
[vector](https://docs-csgo.neverlose.cc/useful-information/script-examples/vector)
{% endcontent-ref %}

## Functions:

### :angles

{% tabs %}
{% tab title="Initialize from" %}
`vec_object:angles(pitch: number, yaw: number):` <mark style="color:purple;">`vector`</mark>

<table><thead><tr><th width="196.60767828800178">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>pitch</strong></td><td><strong><code>number</code></strong></td><td>Pitch component of the angle</td></tr><tr><td><strong>yaw</strong></td><td><strong><code>number</code></strong></td><td>Yaw component of the angle</td></tr></tbody></table>

Converts the angle into a forward vector overwriting the vector's coordinates. Returns itself.
{% endtab %}

{% tab title="Initialize from \[2]" %}
`vec_object:angles(vector: angle):` <mark style="color:purple;">`vector`</mark>

<table><thead><tr><th width="196.60767828800178">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>angle</strong></td><td><strong><code>vector</code></strong></td><td>Angle vector component</td></tr></tbody></table>

Converts the angle into a forward vector overwriting the vector's coordinates. Returns itself.
{% endtab %}

{% tab title="Convert to" %}
`vec_object:angles():` <mark style="color:purple;">`vector`</mark>

Returns the angle vector representing the normal of the vector.
{% endtab %}
{% endtabs %}

### :ceil

`vec_object:ceil():` <mark style="color:purple;">`vector`</mark>

Ceils & overwrites the x, y, and z coordinates of a vector. Returns itself.

### :clone

`vec_object:clone():` <mark style="color:purple;">`vector`</mark>

Creates and returns a copy of the vector.

### :closest\_ray\_point

`vec_object:closest_ray_point(ray_start: vector, ray_end: vector):` <mark style="color:purple;">`vector`</mark>

<table><thead><tr><th width="192.72764796667107">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>ray_start</strong></td><td><strong><code>vector</code></strong></td><td>Ray start position</td></tr><tr><td><strong>ray_end</strong></td><td><strong><code>vector</code></strong></td><td>Ray end position</td></tr></tbody></table>

Returns the vector of the closest point along a ray.

### :cross

`vec_object:cross(other: vector):` <mark style="color:purple;">`vector`</mark>

<table><thead><tr><th width="189.72764796667107">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>other</strong></td><td><strong><code>vector</code></strong></td><td>The vector to calculate the cross product with</td></tr></tbody></table>

Returns the cross product of two given vectors.

### :dist

`vec_object:dist(other: vector):` <mark style="color:purple;">`number`</mark>

<table><thead><tr><th width="186.72764796667107">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>other</strong></td><td><strong><code>vector</code></strong></td><td>The vector to get the distance to</td></tr></tbody></table>

Returns the Euclidean distance between the two given vectors.

### :dist2d

`vec_object:dist2d(other: vector):` <mark style="color:purple;">`number`</mark>

<table><thead><tr><th width="185.72764796667107">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>other</strong></td><td><strong><code>vector</code></strong></td><td>The vector to get the distance to</td></tr></tbody></table>

Returns the 2D distance to another vector.

### :dist2dsqr

`vec_object:dist2dsqr(other: vector):` <mark style="color:purple;">`number`</mark>

<table><thead><tr><th width="185.72764796667107">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>other</strong></td><td><strong><code>vector</code></strong></td><td>The vector to get the squared distance to</td></tr></tbody></table>

Returns the squared 2D distance to another vector.

### :distsqr

`vec_object:distsqr(other: vector):` <mark style="color:purple;">`number`</mark>

<table><thead><tr><th width="185.72764796667107">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>other</strong></td><td><strong><code>vector</code></strong></td><td>The vector to get the squared distance to</td></tr></tbody></table>

Returns the squared Euclidean distance to another vector.

### :dist\_to\_ray

`vec_object:dist_to_ray(ray_start: vector, ray_direction: vector):` <mark style="color:purple;">`number`</mark>

<table><thead><tr><th width="184.72764796667107">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>ray_start</strong></td><td><strong><code>vector</code></strong></td><td>Ray start position</td></tr><tr><td><strong>ray_direction</strong></td><td><strong><code>vector</code></strong></td><td>Ray direction</td></tr></tbody></table>

Returns the distance to a ray.

### :dot

`vec_object:dot(other: vector):` <mark style="color:purple;">`number`</mark>

<table><thead><tr><th width="192.21824447972227">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>other</strong></td><td><strong><code>vector</code></strong></td><td>The vector to calculate the dot product with</td></tr></tbody></table>

Returns the dot product of the two given vectors.

### :floor

`vec_object:floor():` <mark style="color:purple;">`vector`</mark>

Rounds the x, y, and z coordinates of the vector down to the largest integer that is less than or equal. Returns itself.

### :in\_range

`vec_object:in_range(other: vector, range: number):` <mark style="color:purple;">`boolean`</mark>

<table><thead><tr><th width="192.72764796667107">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>other</strong></td><td><strong><code>vector</code></strong></td><td>The vector to calculate the distance to</td></tr><tr><td><strong>range</strong></td><td><strong><code>number</code></strong></td><td>The distance</td></tr></tbody></table>

Returns true if the vector is within the given distance to another vector.

### :init

`vec_object:init(x: number, y: number, z: number):` <mark style="color:purple;">`vector`</mark>

<table><thead><tr><th width="193.60767828800178">Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>x</strong></td><td><strong><code>number</code></strong></td><td>New X coordinate</td></tr><tr><td><strong>y</strong></td><td><strong><code>number</code></strong></td><td>New Y coordinate</td></tr><tr><td><strong>z</strong></td><td><strong><code>number</code></strong></td><td>New Z coordinate</td></tr></tbody></table>

Overwrites the vector's coordinates. Returns itself.

### :length

`vec_object:length():` <mark style="color:purple;">`number`</mark>

Returns the Euclidean length of the vector.

### :length2d

`vec_object:length2d():` <mark style="color:purple;">`number`</mark>

Returns the length of the vector in two dimensions, without the Z axis.

### :length2dsqr

`vec_object:length2dsqr():` <mark style="color:purple;">`number`</mark>

Returns the squared length of the vectors x and y value.

### :lengthsqr

`vec_object:lengthsqr():` <mark style="color:purple;">`number`</mark>

Returns the squared length of the vector.

### :lerp

`vec_object:lerp(other: vector, weight: number):` <mark style="color:purple;">`vector`</mark>

<table><thead><tr><th>Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>other</strong></td><td><strong><code>vector</code></strong></td><td>The vector to interpolate to</td></tr><tr><td><strong>weight</strong></td><td><strong><code>number</code></strong></td><td>A value between 0 and 1 that indicates the weight of <strong>other</strong></td></tr></tbody></table>

Returns the linearly interpolated vector between two vectors by the specified weight.

### :normalize

`vec_object:normalize():` <mark style="color:purple;">`number`</mark>

Normalizes the vector and returns the length of the vector.

### :normalized

`vec_object:normalized():` <mark style="color:purple;">`vector`</mark>

Returns a vector with the same direction as the specified vector, but with a length of one.

### :scale

`vec_object:scale(scalar: number):` <mark style="color:purple;">`vector`</mark>

<table><thead><tr><th>Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>scalar</strong></td><td>number</td><td>The scalar value</td></tr></tbody></table>

Multiplies the vector by the specified scalar.

### :scaled

`vec_object:scaled(scalar: number):` <mark style="color:purple;">`vector`</mark>

<table><thead><tr><th>Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>scalar</strong></td><td>number</td><td>The scalar value.</td></tr></tbody></table>

Returns a copy of the vector multiplied by the specified scalar.

### :to

`vec_object:to(other: vector):` <mark style="color:purple;">`vector`</mark>

<table><thead><tr><th>Name</th><th width="150">Type</th><th width="395.7341676883734">Description</th></tr></thead><tbody><tr><td><strong>other</strong></td><td><strong><code>vector</code></strong></td><td>The vector to get the direction to.</td></tr></tbody></table>

Returns the forward vector from itself to another vector.

### :to\_screen

`vec_object:to_screen():` <mark style="color:purple;">`vector`</mark>

Returns a vector containing the coordinates where the specified position vector appears on the screen.

### :unpack

`vec_object:unpack():` <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>, <mark style="color:purple;">`number`</mark>

Returns the x, y, and z coordinates of the vector. Note that these fields can be accessed by indexing x, y, and z.

### :vectors

`vec_object:vectors():` <mark style="color:purple;">`vector`</mark>, <mark style="color:purple;">`vector`</mark>

Returns the right and up vector of a forward vector.
