From 32991d3e37ed3efd32f5466d1f3ae280e916b4ac Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Thu, 11 Jul 2024 16:56:47 -0500 Subject: [PATCH] Fix: Acceleration needs to be reset to 0 The physics integrator is real scuffed. Nothing has mass, and no forces are applied. Instead, objects affect each other's acceleration. It acts functionally like a force accumulator where everything has a mass of 1. Under this model, it must be cleared each frame so that it can be re-accumulated during the next physics calculation cycle. This bug was spotted because of anomolous behavior of the velocity pointer. Nearly stationary boids would have a rather large (especially after the coefficient reduction earlier) velocity. I noticed this earlier when building the debug tool and thought it was an error in the calculations. There might still be bugs, I still need to test, but that particular one seems to have been a position integrator error. --- src/birdoids_plugin.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/birdoids_plugin.rs b/src/birdoids_plugin.rs index d0faa7a5..2930e4d7 100644 --- a/src/birdoids_plugin.rs +++ b/src/birdoids_plugin.rs @@ -143,11 +143,12 @@ fn turn_if_edge( } fn apply_velocity( - mut query: Query<(&mut Transform, &Velocity, &Acceleration)>, + mut query: Query<(&mut Transform, &Velocity, &mut Acceleration)>, time: Res