Glad you got it sorted. Now just add the sound of bullets whizzing thru the air ......
Bob
]]>dx = x2x1;
dy = y2y1;
goal distance(gd) = Math.sqrt( (dx * dx) + (dy * dy) );
ratio = speed / gd;
ax = ratio * dx;
ay = ratio * dy;
Just had to square the distance, get the square root and then apply a ratio for speed...
Thanks again bob..

 D(x,y)
 /
 /
2 ..... X speed(ax,ay)
 / :
 / :
O(x,y) 2___________________________
(the doted lines can't be straight they are a circle)
(ax+ay) = 4 (total speed)
But ax and ay will change based on the quadrant the destination is in and its angle from the origin.
I cant make a circle but line(OD) will always intersect the circle around the origin based on the speed, which would be the circles radius, and follow the line no matter what angle..
This should be an easy equation and I'm sure its right in front of my face but I can't think of it.. Not enough math practice.
 D1
 D2 D3
> ...........X
 > . D4
 > .
 >.
_________>_____________
'X' would be where 4 would land, which would be wrong.. the '>' would be where ax,ay would need to land in order for the speed to remain the same regardless the Destination 'D'
I cant draw the lines but imagine them from the Origin passing threw a '>' (on the circle radius of speed) to reach a 'D' destination point..
If you use my second equation you can see that's not true, they are not the same and the overall speed is ax+ay ax = 1.18125 ay = 0.79375 total = 2.60625 speed
but the speed changes when the distance is further.. ax = 3.47125 ay = 2.84125 total = 6.3125 speed
I need the bullets to be the same, overall, speed but still reach the destination. 4 would be nice but again there would be no angle and so miss the target...
p.s. Just an example, if ax was 1.25 and ay was 2.75 the total speed would be 4 and so a constant speed with a different angle then
if ax was 2.37 and ay was 1.63 the speed would be the same but the angle would be different and so be what I'm looking for..
I've checked the calcs and my figures are the same for the first two data sets.
ax and ay should always give 4 so the rest are not right. ???
My plan was to split the distance to be covered into n steps. With distance = 400 and s = 40, that would be make t = 10 and n = 100 steps.
So if x1 = 650 and x2 = 250, the distance to be covered is 400, so each step would be an increment of 4
With x1 = 1050 and x2 = 250 D = 800, s=40, t = 20, so n = 200. Each step = 4
What happens if you ignore all the sums and just step 4 each time?
Bob
]]>x1 = 297.25 y1 = 231.75 x2 = 250 y2 = 200 ax = 1.18125 ay = 0.79375
x1 = 388.85 y1 = 313.65 x2 = 250 y2 = 200 ax = 3.4712500000000004 ay = 2.8412499999999996
speed=40;
tx=(x2x1)/speed;
ty=(y2y1)/speed;
ax = (x2x1)/(tx/0.1);
ay = (y2y1)/(ty/0.1);
read out for two different bullets..
x1 = 307.55 y1 = 320.45 x2 = 250 y2 = 200 tx = 1.4387500000000002 ty = 3.0112499999999995 ax=4 ay=4
x1 = 402.85 y1 = 20.4 x2 = 250 y2 = 200 tx = 3.8212500000000005 ty = 4.49 ax=4 ay=4
Yet this does hit target but the speed is still changing..
ax = (x2x1)/40;
ay = (y2y1)/40;
x1=255.35 y1=2.55 x2=250 y2=200 ax = 0.13374999999999987 ay =4.936249999999999
x1=197.65 y1=63.5 x2=250 y2=200 ax = 1.3087499999999999 ay = 3.4125
because the distance is changing
t is computed from the distance and fixed speed so when the distance is small the travel time should be small.
When the target is near are the bullets going faster or slower?
Can you 'dump' your variables for say two bullets only, so you can check the calculations. Get a print out of all the x positions, the value of t, the value of s. Then it may be obvious what is going wrong.
Bob
]]>That should give a constant speed of s.
Bob
]]>would be right but the problem is because the distance changes between x2 and x1 (more then one bullet being shot in each instance) the speed changes for each bullet... and I don't want it to...
]]>Let (x1,y1) be the coordinates of the gun.
And (x2,y2) the coordinates for the target.
Say you want to hit the target in t seconds, advancing the action in 0.1sec jumps.
Then the number of jumps is t / 0.1
The x distance to be covered is x2  x1, so each jump must be (x2  x1) / ( t /0.1) in length.
So position one is x1
Position 2 is x1 + (x2x1) / (t / 0.1)
Position 3 is x1 + 2 times (x2x1) / (t /0.1)
.............................
Last position is x1 + (t/0.1) times (x2x1) /(t/0.1) = x1 + (x2x1) = x2 as required.
The ys can be worked out similarly.
Bob
]]>