The vector (dx,dy) normalized denotes a direction (or, also a velocity with a speed of one), and the vector (dx*speed, dy*speed) denotes velocity. People often mistakenly think that velocity is equal to speed, but it isn't. In a unit-length vector (such as your normalized (dx,dy)) the speed is 1, since that is the length of the vector. If you add that vector to a position, the position will translate by 1 unit; ie, it will move at a speed of 1 unit per frame along the direction (dx,dy). If you scale (dx,dy) by speed then you have a vector whose length is speed. Translating a point by this vector now will move it speed units; ie, it moves at a speed of speed units per frame along the direction indicated by (dx,dy).
alvaro indicated that you need to normalize your (dx,dy) vector to unit length, otherwise the acceleration of the missile's course correction scales by the distance between current position and target position.
Now, in the original posted equations alvaro said to calculate acceleration by
acceleration = spring_constant * vector_to_target - damping_constant * velocity;
This breaks down to:
ax=spring_constant*dx - damping_constant*vx*speed
ay=spring_constant*dy - damping_constant*vy*speed
Where (vx,vy) indicates the current normalized direction vector of the missile (what direction it is currently travelling along) and speed, of course, is the speed of the missile. Correspondingly, he indicated you should calculate the new velocity by:
velocity = velocity + delta_t * acceleration;
This, again, breaks down to:
Note that your velocity will grow, as (vx,vy) will now be non-normalized (ie longer than 1). You should normalize (vx,vy) and either set speed from the length of (vx,vy) before normalization or cap the speed at some maximum, however you want to handle it. Otherwise, the velocity will grow to crazy amounts and your missiles will whizz wildly off the screen.
Edited by JTippetts, 05 January 2013 - 06:51 PM.