Rotating guns and shooting them at the same time?
I put the registration point as the gun's arms. So then the gun would rotate from the arms. But then the bullets come out from the registration point as well. So if I make the registration point on the barrel of the gun, the gun would rotate from the barrel and then shoot from the barrel. So I'm a bit confused where is the right place to place the registration point.
Now what I want would be: Shooting the bullets from the barrel, not the arms. And also rotating by placing an axis on the arms, not the barrel. At the same time.
I tried tweeking it like, bullet.x = x - 100 to make the bullet placed on the barrel and come out from there, but if i rotate let's say (180 degrees) it shoots from the from x - 100 but then the gun is on the other side, so the bullet wouldn't be coming out from the barrel anymore.
I also tried tweeking it by adding a movieclip INSIDE the movieclip gun's barrel so the bullets would come from THAT location, but it shot bullets weirdly and not in the right position.
here is my code, is there any modifications i can put? so it can shoot from the barrel regardless of rotating the gun and changing positions, and also rotate from the arms at the same time? if there is any other solution to tweek it, thanks a lot.
function initialize(e:Event)
{
//add a click listener to the stage
stage.addEventListener(MouseEvent.CLICK, fire);
}
function fire(m:Event)
{
//spawn a bullet
var b = new Bullet;
//set the position and the rotation of the bullet
b.rotation = rotation;
b.x = x;
b.y = y;
//add the bullet to the parent object
parent.addChild(b);
//play the firing animation
play();
}
function update(e:Event)
{
//make the gun face the mouse
if (parent != null)
{
var dx = parent.mouseX - x;
var dy = parent.mouseY - y;
var angle = Math.atan2(dy, dx)/Math.PI * 180
rotation = angle;
}
}
Thank you for reading, sorry if it was long.
