# \[AS3\] first person shooter game, Bullet dirrection towords aim (cursor)

**URL:** https://forum.kirupa.com/t/as3-first-person-shooter-game-bullet-dirrection-towords-aim-cursor/325645
**Category:** programming
**Created:** [October 27, 2011, 1:41pm UTC](https://forum.kirupa.com/t/as3-first-person-shooter-game-bullet-dirrection-towords-aim-cursor/325645 "2011-10-27T13:41:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![kestor](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kestor](https://forum.kirupa.com/u/kestor)
#### Post date: [October 27, 2011, 1:41pm UTC](https://forum.kirupa.com/t/as3-first-person-shooter-game-bullet-dirrection-towords-aim-cursor/325645/1 "2011-10-27T13:41:35Z")

</div>

Hello there.  
I have started a FPS game with CS5.5.  
So far i have done a background, the aim which moves with the mouse and the gun which also moves with the mouse but only on X axis.

But now i have no idea how to start with bullet going from the Gun to the Aim (mouse).  
I know its some trigonometry involved though. I have tried something but only succeded in making the bullets going from the gun at some degrees up.

Can anyone help me on this?

This is the code so far :

```auto

import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.display.Sprite;
import fl.motion.DynamicMatrix;
import flashx.textLayout.accessibility.TextAccImpl;
import flash.display.Sprite;
import flash.display.Shape;
import flash.ui.Mouse;
import flash.events.MouseEvent;

stage.addEventListener(MouseEvent.MOUSE_MOVE, aiming);
Mouse.hide();

function aiming(event:MouseEvent):void
{
    aim.x=mouseX;
    aim.y=mouseY;
    gun1.x=mouseX+225;
    if(aim.x<0)
    {
        aim.x=0;
    }
    if(aim.x>800)
    {
        aim.x=800;
    }
    if(aim.y<0)
    {
        aim.y=0;
    }
    if(aim.y>600)
    {
        aim.y=600;
    }
    if(gun1.x>850)
    {
        gun1.x=850;
    }
    if(gun1.x<110)
    {
        gun1.x=110;
    }
}

stage.addEventListener(MouseEvent.MOUSE_DOWN,pressShoot); 

function pressShoot(event:Event) 
{
    trace("mouse is pressed");
    gun1.gotoAndPlay(2);
}

```

Thanks in advance for any help.
