Skip to content

Commit

Permalink
shared: Fix Vector(2/3).normalize() returning NaNs when dividing by z…
Browse files Browse the repository at this point in the history
…ero (#298)
  • Loading branch information
xLuxy authored Sep 3, 2023
1 parent 54cbf80 commit 7e9417f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion shared/bindings/Vector2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion shared/bindings/Vector3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7e9417f

Please sign in to comment.