From 7e9417f235c47b0c8456dd8f5343034d4404f81f Mon Sep 17 00:00:00 2001 From: Marcel N <67131061+xLuxy@users.noreply.github.com> Date: Sun, 3 Sep 2023 14:07:18 +0200 Subject: [PATCH] shared: Fix Vector(2/3).normalize() returning NaNs when dividing by zero (#298) --- shared/bindings/Vector2.js | 2 +- shared/bindings/Vector3.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/bindings/Vector2.js b/shared/bindings/Vector2.js index f7110589..4be2b62b 100644 --- a/shared/bindings/Vector2.js +++ b/shared/bindings/Vector2.js @@ -111,7 +111,7 @@ alt.Vector2.prototype.inverse = function() { alt.Vector2.prototype.normalize = function() { const length = this.length; - return new alt.Vector2(this.x / length, this.y / length); + return new alt.Vector2(this.x == 0 ? 0 : this.x / length, this.y == 0 ? 0 : this.y / length); } alt.Vector2.prototype.distanceTo = function(vector) { diff --git a/shared/bindings/Vector3.js b/shared/bindings/Vector3.js index eb2a6755..8f65d83b 100644 --- a/shared/bindings/Vector3.js +++ b/shared/bindings/Vector3.js @@ -136,7 +136,7 @@ alt.Vector3.prototype.inverse = function() { alt.Vector3.prototype.normalize = function() { const length = this.length; - return new alt.Vector3(this.x / length, this.y / length, this.z / length); + return new alt.Vector3(this.x == 0 ? 0 : this.x / length, this.y == 0 ? 0: this.y / length, this.z == 0 ? 0 : this.z / length); } alt.Vector3.prototype.distanceTo = function(vector) {