A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Script path of bullet

  1. #1
    Junior Member
    Join Date
    Jun 2000
    Posts
    4

    Script path of bullet

    I'm trying to script de movement of a bullet with a variable angle, variable wind speed.



    this is what I have so far:

    Code:
    // gravity
    var hoek1:Number = 90;
    var grote1:Number = 8;
    
    //Wind 
    var hoek2:Number = 45;
    var grote2:Number = 5;
    
    //krachten uitrekenen
    
    var x1:Number = grote1*Math.cos(hoek1*Math.PI/180);
    var y1:Number = grote1*Math.sin(hoek1*Math.PI/180);
    var x2:Number = grote2*Math.cos(hoek2*Math.PI/180);
    var y2:Number = grote2*Math.sin(hoek2*Math.PI/180);
    
    //optellen krachten x
    var x:Number = x1+x2;
    
    //optellen krachten y
    var y:Number = y1+y2;
    I was thinking that you need to put the angle calculation into the formula. I think it should be a parabolic function. But how do I script it and how do I use my forces in it? I't used for a tanks game for pocket pc so the movie is not standard but 240*320


    Thanx in advanced

  2. #2
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    Location
    Houston!
    Posts
    338
    Still working on a solution to a problem almost exactly like this. I think the solution lies in solving it in pieces. The combination of all the equations you need looks like this:

    V*cos(t) = (a(xs-xf))/(-V*sin(t)+/-sqrt(V^2*sin(t)+2a(ys-yf)))

    You really need to isolate t (the angle needed to get from (xs,ys) to (xf,yf) at a given velocity (V) and gravity (a). You could also solve for velocity if you've already determined t.

    Good luck
    Neal

  3. #3
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    You could use something like this:
    code:

    onClipEvent(load){
    angle=-45;
    angle=angle/180*Math.PI;
    speed=40;
    gravity=2;
    wind=-15;
    }
    onClipEvent(enterFrame){
    xspeed=speed*Math.cos(angle);
    yspeed=speed*Math.sin(angle);
    yspeed+=gravity;
    this._x+=xspeed+wind;
    this._y+=yspeed;
    angle=Math.atan2(yspeed, xspeed);
    speed=Math.sqrt(yspeed*yspeed+xspeed*xspeed);
    }


    Of course the values for speed/angle/gravity/wind should be changed to suit your game.

  4. #4
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    Location
    Houston!
    Posts
    338
    Oh, I guess I didn't read your post entirely. Yeah, tonypa has it right.

    Neal

  5. #5
    Junior Member
    Join Date
    Mar 2005
    Location
    stuckdoingschoolsville
    Posts
    9
    Originally posted by tonypa
    code:
    angle=angle/180*Math.PI;

    what is Math.PI?
    Last edited by allme4myjesus; 05-24-2005 at 06:58 AM.
    no really, I do
    Spam

  6. #6
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Originally posted by allme4myjesus
    what is Math.PI?
    Pi -
    http://en.wikipedia.org/wiki/Pi

    It is used in my post to convert between radians and degrees.
    Math.PI is constant built into Flash.

  7. #7
    Junior Member
    Join Date
    Mar 2005
    Location
    stuckdoingschoolsville
    Posts
    9
    oh, duh, well thanks I needed that
    no really, I do
    Spam

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