> For the complete documentation index, see [llms.txt](https://wiki.thescriptersguild.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.thescriptersguild.com/knowledge/scripting/guides-and-info/calculating-distance-between-two-objects.md).

# Calculating Distance Between Two Objects

Learn how to use Vector3 positions and math nodes to calculate the distance between two objects.

<figure><img src="https://692276616-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FN06Vv6nlwviUQ4hI2Kkd%2Fuploads%2Fgit-blob-74e137057d6f7b94c14119a6cbc4254a8f2c8ecf%2Fcover-tsg-placeholder.jpg?alt=media" alt="Cover image"><figcaption></figcaption></figure>

Finding the distance between two entities requires calculating the difference between their positions and then determining the magnitude of that vector.

## Mathematical Logic

To determine the distance between two objects, you must find the difference between their spatial coordinates and then find the magnitude of that difference.

### Required Nodes

* [Get Object Position](https://github.com/The-Scripters-Guild/ForgeWiki/tree/main/scripting/nodes/math/get-object-position.md): This node is used for both objects to retrieve their current `Vector3` coordinates.
* [Subtract Vectors](/scripting/nodes/math/subtract-vectors.md): Plug the position of Object A into **Operand A** and the position of Object B into **Operand B**. This generates a new `Vector3` representing the direction and distance between them.
* [Get Vector Length](/scripting/nodes/math/get-vector-length.md): Plug the output of the `Subtract Vectors` node into this node. The resulting `Number` is the distance.

***

## Source Data

* Discord thread: [Calculating Distance Between Two Objects](https://discord.com/channels/220766496635224065/1541699500727468032/1541699500727468032)

#### <mark style="color:green;">Contributors</mark>

Guild Archivist
