title: Particle system physics acting weird
body: <p>My particle system's physics update function seems to be incorrect. I'm aiming for all the particles to be attracted towards the mouse.</p>
  
  <p>The particles move towards the mouse pointer just as expected, until they go very near. When they are near, they speed up so much, that they fly far away from the pointer and never return.</p>
  
  <p>Here's the update function:</p>
  
  <pre><code>void updateParticle(particle&amp; p,double time){
      const double G=0.000000000066726;
      const double POINTERMASS=1000000000000;
  
      double squareDistance=pow(p.coords.x-pointerDevice.x,2)+pow(p.coords.y-pointerDevice.y,2)+pow(p.coords.z-pointerDevice.z,2);
      if(squareDistance&lt;0.001)
          squareDistance=0.001;//to fix the possible division by zero
  
      coords_3d_f accelerationVector={p.coords.x-pointerDevice.x,p.coords.y-pointerDevice.y,p.coords.z-pointerDevice.z};
  
      accelerationVector=vector_scalar_multiplication(vector_unit(accelerationVector),((G*POINTERMASS)/squareDistance));
      accelerationVector=vector_scalar_multiplication(accelerationVector,time);
  
      p.velocity=vector_addition(p.velocity,accelerationVector);
  
      p.coords.x-=p.velocity.x*time;
      p.coords.y-=p.velocity.y*time;
      p.coords.z-=p.velocity.z*time;
  }
  </code></pre>
  
  <p>When the squareDistance is constant, the program looks OK, but I know it's false.</p>
  
  <p>So, what am I doing wrong?</p>