 A Flash Developer Resource Site

# Thread: Bullets fired in all directions

1. ## Bullets fired in all directions

Hello, I need help with some thing. I need this so badly. Here is a sample file. Notice how the bullets fly in the direction that the person aims at, can anyone point out what does this? Or could anyone teach me how? I have inspected this game and cannot find the source of it. Please help!!??! Please PM me if you want, it makes it easier for me to find answers. Sometimes I loose the post that I posted in, thanks.
-Brent  Reply With Quote

2. the supplied code is very ugly, but it's inside one of the players (the triangles) actions:

Code:
```		if (Key.isDown(Key.LEFT)) {
_rotation-=rspeed;
}
if (Key.isDown(Key.RIGHT)) {
_rotation+=rspeed;
}```
everytime you press the RIGHT or LEFT arrow key, the rotation is changed according to the rspeed variable. raised if RIGHT, lowered if LEFT.

then, the angle is converted to radians
Code:
`radangle=_rotation/180*Math.PI;`
and whenever you press the SHIFT key, a bullet is fired:
Code:
```if (Key.isDown(Key.SHIFT) && timer<1) {
shots++;
_root.level++;
duplicateMovieClip(_root.shot,"shot"+_root.level,_root.level);
mc=eval("_root.shot"+_root.level);
mc.fired=true;
mc.pn=pn;
timer=maxtime;
}```
using trig, the bullet is placed with the proper orientation (the bold code above)  Reply With Quote

3. Ok, thanks so much. Now can I use this for other games or is there a simpler way of doing it?  Reply With Quote

4. The only parts you would need for tracing the angle would be the RIGHT/LEFT button presses, the conversion from degrees to radians, and then the placement on an x,y plane according to the angle...

Code:
```if (Key.isDown(Key.LEFT)) {
_rotation-=rspeed;
}
if (Key.isDown(Key.RIGHT)) {
_rotation+=rspeed;
}  Reply With Quote

5. And then could I have a variable with all of that as it's value, and then have the bullet shoot to this variable's coordinates?  Reply With Quote

6. This tutorial on flashkit is pretty helpful...
http://www.flashkit.com/tutorials/Ga...u-81/index.php  Reply With Quote

7. That code is in Flash 4 though. I have Flash MX Pro 2004. Where is a tut on that for Flash MX Pro 2004?  Reply With Quote

8. the rotation part of this is the same as what you need...

Code:
```_root.onEnterFrame=function(){
if(Key.isDown(Key.SHIFT)){
//speed of the object when shift is pressed
speed=
}else{
//speed of the object when shift is not pressed
speed=
}
//turns the object counter-clockwise
if(Key.isDown(Key.LEFT)){
._rotation-=speed
}
//turns the object clockwise
if(Key.isDown(Key.RIGHT)){
._rotation+=speed
}
//calculates the direction of the object and moves it forward
if(Key.isDown(Key.UP)){
._x += speed*Math.sin(._rotation*(Math.PI/180));
._y -= speed*Math.cos(._rotation*(Math.PI/180))
}
//calculates the direction of the object and moves it forward
if(Key.isDown(Key.DOWN)){
._x -= speed*Math.sin(._rotation*(Math.PI/180));
._y += speed*Math.cos(._rotation*(Math.PI/180))
}```
taken from:
http://www.flashkit.com/tutorials/Ga...-956/index.php  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap 