{"name":"distanceSqr","title":"distanceSqr","type":"command","url":"https://community.bistudio.com/wiki/distanceSqr","revid":379216,"updated":"2026-10-30T22:25:34Z","groups":["Math - Geometry"],"status":"ok","games":{"arma3":"0.50"},"since":"arma3 0.50","arma3_since":"0.50","description":"Computes the [squared distance](https://en.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance) between two objects or positions.\nThis command is faster than distance by saving a square root operation, useful for mass-checking distance without the need of the distance value itself.","syntaxes":[{"syntax":"var1 distanceSqr var2","params":[{"name":"var1","type":"Object or Position","type_expr":"Object | Position"},{"name":"var2","type":"Object or Position","type_expr":"Object | Position"}],"returns":{"type":"Number","type_expr":"Number","description":"squared distance in square meters or 1e10 if distance cannot be calculated"},"form":"binary","left":{"text":"var1"},"right":{"text":"var2"}},{"syntax":"location1 distanceSqr location2","params":[{"name":"location1","type":"Location or Position","type_expr":"Location | Position"},{"name":"location2","type":"Location or Position","type_expr":"Location | Position"}],"returns":{"type":"Number","type_expr":"Number","description":"squared distance in square meters or 1e10 if distance cannot be calculated"},"form":"binary","left":{"text":"location1"},"right":{"text":"location2"}},{"syntax":"a distanceSqr b","since":"arma3 2.18","params":[{"name":"a","type":"Number","type_expr":"Number"},{"name":"b","type":"Number","type_expr":"Number"}],"returns":{"type":"Number","type_expr":"Number","description":"distance c calculated as `c = a * a + b * b`"},"form":"binary","left":{"text":"a"},"right":{"text":"b"}}],"examples":[{"text":"```sqf\nprivate _distanceSquared = 5 * 5;\nif (player distanceSqr leader player < _distanceSquared) then // similar to player distance leader player < 5\n{\n    hint \"You are less than 5m from the leader!\";\n};\n```","code":["private _distanceSquared = 5 * 5;\nif (player distanceSqr leader player < _distanceSquared) then // similar to player distance leader player < 5\n{\n\thint \"You are less than 5m from the leader!\";\n};"]},{"code":["private _distance = sqrt ((x2 - x1) ^ 2 + (y2 - y1) ^ 2 + (z2 - z1) ^ 2);\nprivate _distanceSqr = (x2 - x1) ^ 2 + (y2 - y1) ^ 2 + (z2 - z1) ^ 2;\n_distance = [x1, y1, z1] distance [x2, y2, z2];\n_distanceSqr = [x1, y1, z1] distanceSqr [x2, y2, z2];\n_distance = sqrt ([x1, y1, z1] distanceSqr [x2, y2, z2]);\n_distanceSqr = ([x1, y1, z1] distance [x2, y2, z2]) ^ 2;"]}],"see_also":["distance","vectorDistanceSqr","distance2D"]}