Ok i have this.
I created this by using this code:
import flash.events.*;
var gunyscale:Number = gun.scaleY;
var power:uint = 10
var velocityX:Number;
var velocityY:Number;
var dy:Number;
var dx:Number;
var ang:Number;
var rot:Number;
velocityX = Math.cos(gun.rotation) * power;
velocityY = Math.sin(gun.rotation) * power;
stage.addEventListener(Event.ENTER_FRAME, moveMouse);
function moveMouse(Event) {
Mouse.hide();
}
stage.addEventListener(Event.ENTER_FRAME, gunRoatate)
function gunRoatate(e:Event):void
{
//Grab the angle
var angle:Number = Math.atan2 (mouseY - gun.y, mouseX - gun.x);
//Rotate the gun, convert angle (in radians) to degrees.
gun.rotation = angle * 180 / Math.PI;
if (gun.rotation < -180 ||gun.rotation > 180)
{
stage.removeEventListener(Event.ENTER_FRAME, gunRoatate)
}
else
{
stage.addEventListener(Event.ENTER_FRAME, gunRoatate)
}
stage.addEventListener(Event.ENTER_FRAME, gunFlip)
function gunFlip(e:Event):void
{
dx = stage.mouseX - gun.x;
dy = stage.mouseY - gun.y;
gun.rotation = Math.atan2(dy, dx) * 180 / Math.PI;
rot = Math.abs(gun.rotation);
if(rot <= 270 && rot >= 90) {
gun.scaleY = -gunyscale;
} else {
gun.scaleY = gunyscale;
}
}
}
function bulletMove(bullet:MovieClip) {
}
As you can see, i am now having trouble firing with it. I want to make it so that when you click with a mouseDown, the bullet fires.
Another thing is getting it to keep firing while holding down the mouse. The tricky thing is the rotation. I don't understand how it is going to leave the gun at the angle.
I was told
velocityX = Math.cos(gun.rotation) * power;
velocityY = Math.sin(gun.rotation) * power;
would allow it to be fired from the angle of the gun, but i am still having trouble.
Help a brotha out.