The forums have permanently moved to forum.kirupa.com. 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.

# Thread: Need help with attaching movieclips for a gun

1. 116
posts
Registered User

## 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. 23
posts
Registered User
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
Last edited by dlgamer; June 28th, 2008 at 09:27 PM.

3. 116
posts
Registered User
thanks for that. I sort of understand it but can you please fill in the code on the flash file(now attached)

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
•