Skip to content

Commit

Permalink
Fix normalization of zero vector that resulted in NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
chooblarin committed Aug 13, 2022
1 parent 8744412 commit 1bcee75
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Mover {
// Computer a vector that points from position to mouse
self.acceleration = mouse - self.position;
// Set magnitude of acceleration
self.acceleration = self.acceleration.normalize() * 0.2;
self.acceleration = self.acceleration.normalize_or_zero() * 0.2;
// Velocity chages according to acceleration
self.velocity += self.acceleration;
// Limit the velocity by top_speed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Mover {
// Computer a vector that points from position to mouse
self.acceleration = mouse - self.position;
// Set magnitude of acceleration
self.acceleration = self.acceleration.normalize() * 0.2;
self.acceleration = self.acceleration.normalize_or_zero() * 0.2;
// Velocity chages according to acceleration
self.velocity += self.acceleration;
// Limit the velocity by top_speed
Expand Down

0 comments on commit 1bcee75

Please sign in to comment.