# Double barrel rotating turret

**URL:** <https://forum.kirupa.com/t/double-barrel-rotating-turret/294854>\
**Category:** Uncategorized\
**Created:** [August 20, 2009, 10:30pm UTC](https://forum.kirupa.com/t/double-barrel-rotating-turret/294854 "2009-08-20T22:30:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThreeDollarBill](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@ThreeDollarBill](https://forum.kirupa.com/u/ThreeDollarBill)\
**Post date:** [August 20, 2009, 10:30pm UTC](https://forum.kirupa.com/t/double-barrel-rotating-turret/294854/1 "2009-08-20T22:30:43Z")

</div>

i am trying to make a “double-barrel” firing cannon in AS3…  
below is a crappy drawing of what im trying to acheive…  
 ![](http://forum.kirupa.com/uploads/kirupa/5730/ab68079bd24addf2.jpg)

im having trouble making the two bullets come out where they should (1 on the left barrel, 1 on the right barrel).

prior to this, i already successfully created a standard “one-barrel” turret that rotates depending on the mouse location and fires 1 bullet per shot… what i’m trying to do now is (like i said above) to create a double-barrel turret that would fire 2 bullets per shot (1 on the gun1 and 1 on gun2)…

if someone has already done this, maybe you can help me out in modifying my code…  
below is the code i used for the single-barrel turret:

on the timeline:

```auto
stage.addEventListener(Event.ENTER_FRAME, followMouse);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fireBullet);
var radians:Number;

function followMouse(event:Event):void
{
    radians = Math.atan2(mouseY - turret.y, mouseX - turret.x);
    var degrees:Number = radians / Math.PI * 180;
    turret.rotation = degrees;
}

function fireBullet(event:KeyboardEvent):void
{
    var newBullet:MovieClip = new Bullet();
    newBullet.x = Math.cos(radians) * 93.5 + turret.x;
    newBullet.y = Math.sin(radians) * 93.5 + turret.y;
    newBullet.rotation = turret.rotation;
    addChild(newBullet);
}

```

on the Bullet class

```auto
package
{
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    
    public class Bullet extends MovieClip
    {
        var xSpeed:Number;
        var ySpeed:Number;
        var angle:Number;
        public var speed:Number;
        
        public function Bullet()
        {
            speed = 30;
            this.addEventListener(Event.ADDED, initializeBullet);
        }
        
        function initializeBullet(event:Event):void
        {
            angle = this.rotation / 180 * Math.PI;
            xSpeed = Math.cos(angle) * speed;
            ySpeed = Math.sin(angle) * speed;
            this.addEventListener(Event.ENTER_FRAME, moveBullet);
        }
        
        function moveBullet(event:Event):void
        {
            if (this.x > 550)
            {
                this.removeEventListener(Event.ENTER_FRAME, moveBullet);
                this.parent.removeChild(this);
            }
            else
            {
                this.x += xSpeed;
                this.y += ySpeed;
            }
        }
    }
}

```
