My first guess would be that you need to switch around the cos and sin in the velocity calculation, like so. (That's usually the way things work with atan2.)
1 2
| xVelocity += Math.cos(angle) * ACCELERATION; yVelocity -= Math.sin(angle) * ACCELERATION; |
However, that doesn't seem to agree with the "Result" angles that you've given in your example, so I'm not confident that it will solve the problem.
Also, you should be able to remove the minus signs from y1, y2 and yVelocity since they should all cancel out.
If you put a debugging line in the code to print out (x1,y1), (x2,y2), (x,y), angle, and (xVelocity,yVelocity), it should make it clearer what's going on.
For what it's worth, I believe that the following two bits of code should both make a bullet fly towards a target.
1 2 3 4 5
| double dx = xTarget - xBullet; double dy = yTarget - yBullet; double angle = Math.atan2(dy,dx); double xVelBullet = speed*Math.cos(angle); double yVelBullet = speed*Math.sin(angle); |
1 2 3 4 5 6
| double dx = xTarget - xBullet; double dy = yTarget - yBullet; double d = Math.sqrt(dx*dx + dy*dy); d = Math.max(d, 1.0e-6); double xVelBullet = speed*dx/d; double yVelBullet = speed*dy/d; |