# Shooter problems, help!

**URL:** https://forum.kirupa.com/t/shooter-problems-help/204120
**Category:** Uncategorized
**Created:** [October 17, 2006, 8:48am UTC](https://forum.kirupa.com/t/shooter-problems-help/204120 "2006-10-17T08:48:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Gorefest](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@Gorefest](https://forum.kirupa.com/u/Gorefest)
#### Post date: [October 17, 2006, 8:48am UTC](https://forum.kirupa.com/t/shooter-problems-help/204120/1 "2006-10-17T08:48:30Z")

</div>

Hey guys, i’ve got an annoying little problem. I am trying to make a game where you can walk with a MC and rotate the arm with a gun and shoot. The rotating works fine outside of a MC but when I place it inside a MC it’s screwed up!:S Can anyone help me?

Actions from the gun:

onClipEvent (mouseMove) {  
Xd =\_root.\_xmouse-\_x; //Get \_x distance from gun to mouse  
Yd =\_root.\_ymouse-\_y; //Get \_y distance from gun to mouse  
radAngle = Math.atan2(Yd, Xd); //Use atan2 to calculate the angle from gun to mouse  
\_rotation = int((radAngle_360 / (2_Math.PI))+90); //Use PI to calculate and set gun rotation  
updateAfterEvent();  
}

Actions from the bullet:

onClipEvent(load){  
spd=20; //bullet speed  
\_x=\_root.gun.\_x; //Move to gun \_x  
\_y=\_root.gun.\_y; //Move to gun \_y  
\_rotation= \_root.gun.\_rotation; //Point in same direction as gun  
}  
onClipEvent(enterFrame){  
if(\_name == “bullet”){  
\_x = -1000; //Move the original bullet MC offstage  
}else{  
//Run this movement code on all dupes  
if (\_rotation\>180) {  
\_y += (spd_Math.cos( Math.PI/180_\_rotation));  
\_x -= (spd_Math.sin( Math.PI/180_\_rotation));  
} else {  
\_y -= (spd_Math.cos (Math.PI/180_\_rotation));  
\_x += (spd_Math.sin( Math.PI/180_\_rotation));  
}  
}  
if(\_x\>Stage.width || \_x\<0 || \_y\<0 || \_y\>Stage.height){  
//If off-stage, delete the dupe to save CPU  
this.removeMovieClip();  
}

}

Actions on the first frame of the maintimeline:

var bc=1000; //bulletcount  
\_root.onMouseDown=function(){  
bc++;  
if(bc\>1100){ bc=1000; } //Reset bulletcount  
duplicateMovieClip(“bullet”, “b”+bc, bc); //Create dupe bullet  
}

WHAT AM I DOING WRONG? AND HOW CAN I FIX THIS?!:puzzled:

---

<div class="post-metadata">

### Author: ![Zaxza](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/zaxza/32/2227_2.png) [@Zaxza](https://forum.kirupa.com/u/Zaxza)
#### Post date: [October 24, 2006, 7:26pm UTC](https://forum.kirupa.com/t/shooter-problems-help/204120/2 "2006-10-24T19:26:35Z")

</div>

This is Denvishes code from new grounds…  
Many people had the same problem. I made a different code based on the \_ymouse possition. So it only rotates to a 45 degree and a vertical angle. I’m having problems when i invert the characters \_xscale the bullets change direction. Any tips on stopping this?
