### Velocity Verlet Integration

closed account (2NywAqkS)
I'm new to the idea of Velocity Verlet Integration, whereas before I was apparently using Euler's method. After finding out about this I returned to an asteroid gravity simulation(whereby every asteroid is gravitationally attracted to every other on) I'd made a while ago and tried to implement the integration. However it doesn't quite work and I get get some odd results. Not insane, but not what I'd expect in real life.
I'm following this tutorial;
http://buildnewgames.com/gamephysics/

 ``123456789101112131415161718192021222324252627282930`` ``````lastAcceleration = avgAcceleration; position.x += velocity.x * dT + ( 0.5 * lastAcceleration.x * dT * dT); position.y += velocity.y * dT + ( 0.5 * lastAcceleration.y * dT * dT); // Calculate New Acceleration for(unsigned int i = 0; i < asteroidVector.size(); i++) { if (i != id) // Stops asteroid from caclulating it self { float dx = asteroidVector[i].position.x - position.x; float dy = asteroidVector[i].position.y - position.y; float direction = fast_atan2f(dy, dx); float distanceSquared = (dx*dx + dy*dy); if (distanceSquared < 200.0f) { continue; // This stop the asteroids fly off when they collide } float force = 100.0f * ((mass * asteroidVector[i].mass)/distanceSquared); newAcceleration.x = (force / mass) * cos(direction); newAcceleration.y = (force / mass) * sin(direction); } } avgAcceleration.x = (lastAcceleration.x + newAcceleration.x) / 2.0; avgAcceleration.y = (lastAcceleration.y + newAcceleration.y) / 2.0; velocity.x += avgAcceleration.x * dT; velocity.y += avgAcceleration.y * dT;``````