You are not logged in.
Pages: 1
Ahh ha.. I got it...
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..
Basically I need to plot out a rise over run to meet an angle.. The intersecting point on the line from origin to destination would be the product of the sum of the rise pluss the run which would be an distance equivalent to the speed.

 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..
Your angle never changes.. In each step you have to increase or decrease from the origin to the destination, if each step for ax or ay is always 4 then the angle is always the same.. Which isn't true in every instance.
That is why I named them ax (angle x) and ay (angle y) because they are representing velocities to the angle needed to reach the destination. In the simplest terms, I'm thinking ax should never be more then 2 or less then 2, (well I guess they could as long as they are together not more then 4) same for ay. Adding ax to ay it should always be an equivalent of 4, as that is a representation of the speed.
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 think the compiler is changing the number because its out of range or something.. I tried var:Number and var:Int .. had no effect on the number.. but I'm not sure why one is out of range and the other isn't..
Another example of the second equation... ax = (x2x1)/40; a bullet near and far...
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
ok I tried it again.. and this is way off not even hitting target..
equation
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
I guess I shouldn't be complaining because the bullets are right on target.. but I just think it looks strange when the bullets are traveling at different speeds.
You would think so but its not happening.. and I'm not sure why.. like I said the only thing I can think of is because the distance is changing..
as in.. bullet one is shot when x1 is relatively close to x2, the speed of the bullet is slow.... but bullet 2 is shot when x1 is far from x2 and the speed is fast.. I want both bullets to be traveling at the same speed, regardless of the distance.
p.s. and still be on target..
Ok lets just substitute time with speed...
so
x1+(x2x1)/s
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...
but I just tried this and its not working... its close.. but the speed of the bullet still changes the further away the faster the bullet is... (btw it still misses)
ax = ((target.xx)/(sw+1))*10;
ay = ((target.yy)/(sh+1))*10;
I can't negate the distance from change the speed of the bullet.
the bullet needs to travel,, for x ... Dx  Ox = total distance... Now that distance changes so if I divide by a constant the speed should be constant, right? (DxOx) / sw like the screen width... and same for y .. (Dy  Oy)/ sw ... and I can change the speed by adding or subtracting from screen width... or what I did original was change the value of the total distance.. But I think there should be another way to do that..
I don't want the angle... The velocity will form the angle.. as the object moves threw each point until it hits the target. But I need to know how to calculate the velocity for both x and y so they together move each step till they meet the target. .. like step 1) x + .01, y + .002, step 2) x+ .01, y+.002 .. and so on.. I know how to calculate the angle but I don't know how to find the values to add to x and y a.e. the .01 and .002... for the constant velocity.
The program is a bullet and target. What I want is a constant velocity(vx,vy) for an object(bullet) moving from an origin point to a destination.. It should be simple rise over run and then and something for the speed of the object(bullet).. What I'm using changes the speed of the object(bullet) and that's not right, the speed changes because the distance between the origin and destination change. What I want is a constant speed. So now I'm thinking I need to?? divide the speed into the equation to give each step a constant speed regardless of the distance??
But that's not right.. I even tried dividing by the screen width and height .. then applying the speed... its still off and the original is still better.
not working.... I guess the magnitude in the original would be the speed.. and again I'm dividing by the screen width... what it appears is happening is that the speed still changes on the distance they are apart, so o.x  d.x is giving me the distance they are apart.. I want perhaps the square root of that? or something?? I dont want the distance between o.x and d.x ... but the vector angle so.. vectorO, vectorD and vectorA ??? figure out vector angle if it's position is dependent on the speed..?? humm...
i guess the simplest terms would be a.x = O.x  D.x and y.x = O.xD.x ... then (a.x,a.y)* Speed = vector... as I'm thinking about it...
Thank you..
I'm not sure how to word this question.. I know the speed I want... but I want, not just the the angle from Opoint to Dpoint but the x,y vector if they are moving at some speed S..
the Origin point is at some angle (x,y) to destination point. What would be the angle in (x,y)? I'm amusing x and y would be a single digit numbers and because the destination would change either positive or negative in value. I'm coding in C++ and it works but it has the wrong speed, I need to apply the speed to the angle (x,y) to get my vector. How is this done? Or what other wording do I need to express this?
current code, which is wrong but it works for now, but the speed is wrong when the distance between the two points increases. ax = ((xdestination.x)*16)/(sw+1) ay = ((ydestination.y)*12)/(sh+1)
I don't think I need the screen width or height but its working this way.. and the multiples 16 and 12 are a magnitude of some sort, again I narrowed it in to get them and they would be pointless if I can just get the angle in x,y...
Dp
 /
 /
 a(x,y) *speed = vector
Op______
Angle (x,y) I guess is unknown and would be dependent on the speed to make it a vector differential? but what would (x,y) be if I just wanted it in the simplest of terms? Because then I could just multiply that with the speed for the vector I need. I tried looking it up but I keep finding atan2 giving the angle, which isn't the problem, how do I express that angle in (x,y)?
I need angle x and angle y to figure out the differential , if I'm applying s for speed.. I complicate things sorry..
Ax
∑ Ay
s>
lol or would that be
O.x,O.y
∑ D.x,D.y
s>
Pages: 1