A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: simple help

  1. #1
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    simple help

    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

  2. #2
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    Long time ago, I ever replied similar thread in actionscript forum.

    The calculation is not simple.

    Anyway, here is the zip file , I posted. I have forgot the equation formula.
    Attached Files Attached Files

  3. #3
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    Ideally this would be a calculation for velocity.y for a given velcoity.x,target.x and target.y
    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;

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    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.

  5. #5
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    Yes, I mean velocity.x and velocity.y;

    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.

    Then velocity.y=(target.y-origin.y)/t;

  6. #6
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    Thanks

    Thanks this is now working. Only had to make one minor adjustment to check if vx needed to be positive or negative and it works great thanks tons!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center