dimanche 27 avril 2014

How to make character shoot facing the right direction in AS3?


Vote count:

0




I am making a flash game and I have a game character similar to this


http://ift.tt/1imaUKX


The character is able to shoot when facing left,and the bullet is shot diagonally from the direction of the gun.


However, when my character faces right, the bullet is shot from the back of the head rather than the gun itself. I did realise that when the character is facing right, the registration point is on the gun but when facing left, the registration point is on the back of her head. Could that be a problem? And how do i overcome this?


Here is my code



function shootBulletBoy():void {

var fire:myBullet2 = new myBullet2();
fire.x = GirlHero.x;
fire.y = GirlHero.y;
addChild(fire);
fire.addEventListener(Event.ENTER_FRAME, moveBullet2);
}

function moveBullet2(e:Event):void {

if (GirlHero.currentLabel == ('left')){
e.currentTarget.x += Math.cos(rads) * speed;
e.currentTarget.y += Math.sin(rads) * speed;
e.currentTarget.rotation = 265;
}

if (GirlHero.currentLabel == ('right')){
e.currentTarget.x += Math.cos(radss) * speedd;
e.currentTarget.y += Math.sin(radss) * speedd;
}}


Another issue that I am having is that when my character is facing left and shoots, the gun shoots in the left direction however if the character turns right whilst the bullet is still up in the air, my bullet all of a sudden turns in the rights direction. I don't know why its doing this.


Sorry if im asking too much. You dont have to answer both my problems, a little help would do :)


Thank you



asked 56 secs ago






Aucun commentaire:

Enregistrer un commentaire