Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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:
    Code:
    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 kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012