View Full Version : [AS3] Bullet Firing
dilpreet
09-13-2009, 06:37 AM
Hey
i have a movie clip called soldier which includes the main body of the soldier and the arm. The arm is a movie clip which also holds the gun so the rotation is the same as the mouse rotates but my problem is when i fire the bullet i can still control it's rotation by moving the mouse. So is their a way to make the bullet outside the arm movie clip so after the bullet is fired you have no control over the rotation of the bullet
thanks
lordofduct
09-13-2009, 06:51 AM
only get the mouse position at the point of which the gun is fired.
Store that value somewhere
then update position via that value, instead of getting the mouse position over and over.
dilpreet
09-13-2009, 07:17 AM
this is my code
var bullet:Array=new Array()
var c:Number=0
var speed:Number=60
stage.addEventListener(MouseEvent.MOUSE_DOWN,shoot )
function shoot(e:Event)
{
var gunR:Number = gun.rotation
var gunX:Number = gun.x
var gunY:Number = gun.y
c++
bullet[c]=new Bullet()
bullet[c].rotation=gunR
bullet[c].num=c
bullet[c].xspeed = speed * Math.cos((gunR) * Math.PI / 180);
bullet[c].yspeed = speed * Math.sin((gunR) * Math.PI / 180);
bullet[c].x=gunX+(bullet[c].xspeed)*2
bullet[c].y=gunY+(bullet[c].yspeed)*2
addChild(bullet[c])
bulletTimer.start();
bullet[c].addEventListener(Event.ENTER_FRAME,fire)
}
function fire(e:Event)
{
Object(e.target).x+=Object(e.target).xspeed
Object(e.target).y+=Object(e.target).yspeed
}
inside the arm movie clip and it still doesn't work
newblack
09-13-2009, 01:54 PM
you need to not nest the bullet inside of a rotating DisplayObject if you don't want it to rotate! add the bullet at your game's world level instead.
dilpreet
09-13-2009, 10:05 PM
So u want me to add the bullet in the level not the arm. I know it seems dumb but could u give me an example
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.