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.
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 = bulletSpeedsin(gunAngle) and
xSpeed = bulletSpeedsin(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
thanks for that. I sort of understand it but can you please fill in the code on the flash file(now attached)