A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Question about Projectiles

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Posts
    25

    Question about Projectiles

    I was just wondering what type of mathematical computations/physics I need to know for determining a projectile's path and trajectory.
    Last edited by shinobitaichou; 09-21-2009 at 12:35 PM.

  2. #2
    my x booty it is that BIG
    Join Date
    Jun 2004
    Location
    New York
    Posts
    696
    the x and y initial position of the bullet
    the speed
    the path it will travel through either x and/or y
    the destination of the bullet
    and the condition the will trigger the bullet
    Project||[GAME]-on hold for now
    ------------------
    [Hero]-80%
    [Enemies]-1%
    [Weapons]-90%
    [Items]-0%
    [Levels]-10%

  3. #3
    Junior Member
    Join Date
    May 2009
    Posts
    24
    to do this all you need is trig...
    M
    ............./|
    .........../..|
    ........./....|
    ......./......|Y
    ...../........|
    O /A_____|
    X
    take this badly drawn ascii triangle were 'O' is the origin of the shot 'M' where the aimer/mouse is and 'A' is the angle.

    what you need to do is find 'A'

    to do this you use

    atan2(Y,X)

    (or if its based of a characters rotation use the characters rotation as A)

    then to get the projectile to move:

    Math.sin(iAngle * (Math.PI/180))

    this will give you the amount you need to increment the x value by every frame

    Math.sin(iAngle * (Math.PI/180))

    for the y increment:

    Math.cosn(iAngle * (Math.PI/180)) *-1

    so all up (pretend that this is based off char rotation and the

    Code:
    addEventListener(Event.ENTER_FRAME,eFrame)
    addEventListener(MouseEvent.MOUSE_DOWN, shootOn);
    
    function eFrame(evt:Event){
         projectile .x+=xInc
         projectile .y+=yInc
    }
    
    
    function shootOn(evt.MouseEvent){
         var xInc:Number = Math.sin(charRotation* (Math.PI/180)) 
         var yInc:Number = Math.cos(charRotation* (Math.PI/180)) * 1;
    }
    of course you realise that you will need to do that properly but thats the general gist of that.

    for other things like gravity just do somthing like

    Code:
    yInc+=gravity
    for bouncing projectlies

    Code:
    if (projectile.y == ground){
         yInc = -yInc * bounceDecay // 0.4 or something like that
    }
    i hope that helps i will once again say that it is all really rough so dont dig into me for that its just there to give you an idea of what to do

  4. #4
    Junior Member
    Join Date
    Nov 2008
    Posts
    25
    Thank you, buk.

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