# Trigger continues turret fire

**URL:** <https://forum.kirupa.com/t/trigger-continues-turret-fire/230655>\
**Category:** programming\
**Created:** [June 27, 2007, 11:00pm UTC](https://forum.kirupa.com/t/trigger-continues-turret-fire/230655 "2007-06-27T23:00:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zach93111](https://avatars.discourse-cdn.com/v4/letter/z/e0b2c6/32.png) [@zach93111](https://forum.kirupa.com/u/zach93111)\
**Post date:** [June 27, 2007, 11:00pm UTC](https://forum.kirupa.com/t/trigger-continues-turret-fire/230655/1 "2007-06-27T23:00:34Z")

</div>

I have a turret that fires every time a characters enters a radius the gun begins to fire. I have gotten the turret to aim at the turret and have gotten the bullet to be attached to the turret. But I cannot get it to fire the bullet at the character and do it in rounds such as 2 bullets per second or so on. Heres the script of what I got…

onClipEvent (load) {  
xDest = \_root.robot.\_x;  
yDest = \_root.robot.\_y;  
this.\_alpha = 100;  
}  
onClipEvent (enterFrame) {  
rx = \_root.robot.\_x;  
ry = \_root.robot.\_y;  
cx = \_root.enemy.\_x;  
cy = \_root.enemy.\_y;  
angle = Math.atan2(ry-cy, rx-cx)/(Math.PI/180);  
\_rotation = angle;  
distance = 50;  
rx = \_root.robot.\_x;  
ry = \_root.robot.\_y;  
tx = \_root.enemy.\_x;  
ty = \_root.enemy.\_y;  
if (Math.sqrt((rx-tx)_(rx-tx)+(ry-ty)_(ry-ty))\<distance) {  
\_root.enemy.gotoAndPlay(2);

```
    firepower = Math.sqrt(_root.robot._x*_root.robot._x+_root.robot._y*_root.robot._y);
    if (firepower&gt;200) {
        firepower = 200;
    }
    start_ball_x = _root.enemy.Start_Bullet._x;
    start_ball_y = _root.enemy.Start_Bullet._y;
    cannonball_fired = attachMovie("Ball_Canon", "Ball_Canon"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_ball_x, _y:start_ball_y});
    cannonball_fired._x += (xDest-cannonball._x)*.1;
    cannonball_fired._y += (yDest-cannonball._y)*.1;
}

```

}
