Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions engine/physics/physics_engine.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use nalgebra::Vector2;

/// Minimum distance threshold to avoid division by very small values in collision calculations
const MIN_DISTANCE_EPSILON: f32 = 1e-6;

#[derive(Clone, Debug)]
pub struct Object {
pub position: Vector2<f32>,
Expand Down Expand Up @@ -66,7 +69,7 @@ impl PhysicsEngine {
let rad2 = self.objects[j].radius;
let diff = pos1 - pos2;
let distance = diff.norm();
if distance < rad1 + rad2 && distance > 0.0 {
if distance < rad1 + rad2 && distance > MIN_DISTANCE_EPSILON {
// Elastic collision in 2D
let m1 = self.objects[i].mass;
let m2 = self.objects[j].mass;
Expand Down Expand Up @@ -123,7 +126,7 @@ impl PhysicsEngine {
}

// Handle object-object collisions
// self.handle_collisions();
self.handle_collisions();

for obj in &self.objects {
log::info!(
Expand Down
Loading