I have a projectile with x and y velocities. I have a starting x,y and a target x,y isn't there a simple formula to set the x and y velocities to move it to the target x and y? Ideally this would be a calculation for velocity.y for a given velcoity.x,target.x and target.y
Originally posted by ericlin Wow, if the velocity x, target.x and target.y are know, the equation to get initial velocity y is simple.
t=(target.x-origin.x)/vx;
then
target.y=origin.y+vy*t+(g*t*t)/2;
so, vy=((target.y-origin.y)-(g*t*t/2))/t;
I figured it was simple for someone that knows their math.
Help me here what is g and how do I get it. If this is gravity, I don't need any gravity effect so what would I use here? I assume vx is velocity.x and vy is velocity.y for my projectile.
g is gravity. Or, we can call it "acceleration". Because you want a "projectile" curve, there must be an "acceleration". In real world, that is "gravity - 0.98". In flash world, you can give it any value you like. If you give g a large positive value, the projectile curve is sharp. If you give g a small value, the projectile curve will be nearly a straight line. If you give g a negative value, the curve will goes up.
If you omit g, then it is not projectile. It shoot the target directly.