The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 3 of 3

Thread: Need help with attaching movieclips for a gun

  1. #1

    Need help with attaching movieclips for a gun

    I really need some help in making a bullet that would fire out of the gun towards the angle the gun is at. I have not found a tutorial that shows how you can do this. Any help will be much appreacheated. I have attached the fla file so if you want to alter any of the code feel free to. After you have changed it reply to this and attach the file. thanks.

  2. #2
    You can use the law of cosines to find the x and y movement per frame from the total movement per frame (a/sinA = b/sinB = c/sinC) Law Of sines.
    If this math is al little advanced for you It's okay I will walk you thru it. (look at the bitmap for a visual explanation)

    using this math:
    bulletSpeed/sin(90) = ySpeed/sin(gunAngle) = xSpeed/sin(90-gunAngle)

    this simplifies to:
    ySpeed = bulletSpeed*sin(gunAngle) and
    xSpeed = bulletSpeed*sin(90-gunAngle)

    to calculate find the sine in flash use Math.sin()

    One problem You will have is that when you get a decimal for xSpeed or ySpeed the >_x and _y coordinated will be rounded off. To get a more accurate result do something like:
    bullet_mc.onEnterFrame = function()    {
        xPos += xSpeed;
        yPos += ySpeed;
        this._x = xPos;
        this._y = yPos;
    oh, and by the way, you didn't include the flash file
    Attached Images Attached Images  
    Last edited by dlgamer; June 28th, 2008 at 09:27 PM.

  3. #3
    thanks for that. I sort of understand it but can you please fill in the code on the flash file(now attached)
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012