Garry's Mod Wiki

Vector:DistToSqr

number Vector:DistToSqr( Vector otherVec )

Description

Returns the squared distance of 2 vectors, this is faster than Vector:Distance as calculating the square root is an expensive process.

Arguments

1 Vector otherVec
The vector to calculate the distance to.

Returns

1 number
Squared distance to the vector

Example

Checks if a player is within dist units of another player in the most efficient way possible.

function PlayerWithinBounds(ply,otherPly, dist) return ply:GetPos():DistToSqr(otherPly:GetPos()) < (dist*dist) -- This is computationally faster than: -- ply:GetPos():Distance(otherPly:GetPos()) < dist end print(PlayerWithinBounds(Entity(1),Entity(2),500))
Output: true

Page Links


Special Pages


Wikis

?

Render Time: 49ms

DB GetPage 12
Generate Html 9
SaveChanges (1) 13
Render Body 0
Render Sidebar 12