Skip to content

Commit

Permalink
Fix division by 0 error
Browse files Browse the repository at this point in the history
  • Loading branch information
GaspardCulis committed Sep 22, 2023
1 parent 3678213 commit cfd6222
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/gravity.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def update_forces(self, delta: float):
force = Vector2(0, 0)
for o in filter(lambda x: not (x.passive or x == self), PhysicsObject.all_objects):
distance = self.position.distance_squared_to(o.position)
f = G * (self.mass * o.mass) / distance
f = G * (self.mass * o.mass) / max(distance, 0.1)
force += f * (o.position - self.position).normalize()

self.velocity += (force / self.mass) * delta
Expand Down

0 comments on commit cfd6222

Please sign in to comment.