# Shooting Bullets at the Mouse

**URL:** <https://forum.kirupa.com/t/shooting-bullets-at-the-mouse/184173>\
**Category:** programming\
**Created:** [April 2, 2006, 11:41pm UTC](https://forum.kirupa.com/t/shooting-bullets-at-the-mouse/184173 "2006-04-02T23:41:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![habes](https://avatars.discourse-cdn.com/v4/letter/h/e5b9ba/32.png) [@habes](https://forum.kirupa.com/u/habes)\
**Post date:** [April 2, 2006, 11:41pm UTC](https://forum.kirupa.com/t/shooting-bullets-at-the-mouse/184173/1 "2006-04-02T23:41:16Z")

</div>

Hi everyone.  
I need to make a bullet that will shoot in the direction of the mouse.  
So far I have pretty much everything else.  
Can someone explain what I should do?  
Ill post the swf and fla, right now the bullet doesnt move, targets are “respwaned” on release at the momment.

[URL=“[http://www.filefactory.com/get/v3/h.php?f=369e5bbfabddfb86fc83b06c&b=3&c=a4c3f6cd326a6fdb](http://www.filefactory.com/get/v3/h.php?f=369e5bbfabddfb86fc83b06c&b=3&c=a4c3f6cd326a6fdb)”][http://www.savefile.com/files.php?fid=8847094](http://www.savefile.com/files.php?fid=8847094)

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 3, 2006, 12:53am UTC](https://forum.kirupa.com/t/shooting-bullets-at-the-mouse/184173/2 "2006-04-03T00:53:34Z")

</div>

:sc:

---

<div class="post-metadata">

**Author:** ![habes](https://avatars.discourse-cdn.com/v4/letter/h/e5b9ba/32.png) [@habes](https://forum.kirupa.com/u/habes)\
**Post date:** [April 3, 2006, 2:49am UTC](https://forum.kirupa.com/t/shooting-bullets-at-the-mouse/184173/3 "2006-04-03T02:49:30Z")

</div>

Thanks Canadian but i cant open it… i have flash MX

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 3, 2006, 2:58am UTC](https://forum.kirupa.com/t/shooting-bullets-at-the-mouse/184173/4 "2006-04-03T02:58:07Z")

</div>

```auto
var depth = 0;
onMouseDown = function () {
 var b = this.attachMovie("bullet", "bullet" + depth, depth++);
 b._x = Stage.width / 2, b._y = Stage.height / 2;
 b._t = Math.atan2(this._ymouse - b._y, this._xmouse - b._x);
 b.onEnterFrame = function() {
  this._x += Math.cos(this._t) * 3;
  this._y += Math.sin(this._t) * 3;
 };
};

```

You’ll need a movie clip in the library with the the linkage id\* bullet\*.

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [April 3, 2006, 4:00am UTC](https://forum.kirupa.com/t/shooting-bullets-at-the-mouse/184173/5 "2006-04-03T04:00:11Z")

</div>

or a shorter method:

```auto

var depth = 0;
onMouseDown = function () {
 var b = this.attachMovie("bullet", "bullet" + depth, depth++, {_x:Stage.width / 2, _y:Stage.height / 2, _t:Math.atan2(this._ymouse - b._y, this._xmouse - b._x), onEnterFrame:function() {
  this._x += Math.cos(this._t) * 3;
  this._y += Math.sin(this._t) * 3;
 };});
};

```

---

<div class="post-metadata">

**Author:** ![habes](https://avatars.discourse-cdn.com/v4/letter/h/e5b9ba/32.png) [@habes](https://forum.kirupa.com/u/habes)\
**Post date:** [April 3, 2006, 4:58am UTC](https://forum.kirupa.com/t/shooting-bullets-at-the-mouse/184173/6 "2006-04-03T04:58:12Z")

</div>

thanks guys but that wont work, or i dont know how to

i need the bullet to be generated from the point of the gun (see swf) and i need it to move with the character (i attached a new swf with a moveable char. w,a & d to move)

i bet theres an easy way to do this, just not sure how

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 3, 2006, 5:01am UTC](https://forum.kirupa.com/t/shooting-bullets-at-the-mouse/184173/7 "2006-04-03T05:01:50Z")

</div>

> [@nathan99](#):
>
> or a shorter method:

Err, that’s exactly the same . . .

---

<div class="post-metadata">

**Author:** ![habes](https://avatars.discourse-cdn.com/v4/letter/h/e5b9ba/32.png) [@habes](https://forum.kirupa.com/u/habes)\
**Post date:** [April 3, 2006, 5:17am UTC](https://forum.kirupa.com/t/shooting-bullets-at-the-mouse/184173/8 "2006-04-03T05:17:58Z")

</div>

_bump_ i think you posted right after me canadian

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [April 3, 2006, 6:07am UTC](https://forum.kirupa.com/t/shooting-bullets-at-the-mouse/184173/9 "2006-04-03T06:07:17Z")

</div>

> [@TheCanadian](#):
>
> Err, that’s exactly the same . . .

Lol, Yeah it’s the same… but shorter.
