Public Group

# [Flash AS 2.0]Cant shoot bullet when accelerating and moving counter-clockwise

This topic is 3963 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I can shoot a bullet when rotating on the spot either clockwise or counter-clockwise, I can even shoot while accelerating forwards as well as rotating clockwise. My problem is, my ship doesn't feel like shooting when traveling forwards and rotating counter-clockwise. You can see what I mean here. UP - Accelerate LEFT - Rotate Counter-Clockwise RIGHT - Rotate Clockwise SPACE - Shoot I have a ship movie clip on my stage which has the following actionscript applied:
// Ships load event handler
var maxSpeed = 8;
var speed = 0;
var slowDownSpeed = 0.3;
var accelerateSpeed = 2;
var turnSpeed = 5;
}

// Ships enterFrame event handler
onClipEvent(enterFrame){
// Shoot a bullet from this ships position
if(Key.isDown(Key.SPACE)){
_root.spawnBullet(this._x, this._y, this._rotation);
}

// Accelerate if Up is pressed otherwise slowdown
if(Key.isDown(Key.UP)){
if(speed <= maxSpeed-accelerateSpeed){
speed += accelerateSpeed;
}
else
{
speed = maxSpeed;
}
}
else
{
if(speed > slowDownSpeed){
speed -= slowDownSpeed;
}
else
{
speed = 0;
}
}

// Rotate the ship counter-clockwise
if(Key.isDown(Key.LEFT)){
this._rotation -= turnSpeed;
}

// Rotate the ship clockwise
if(Key.isDown(Key.RIGHT)){
this._rotation += turnSpeed;
}

// Move the ship to its next position
var angle = this._rotation*Math.PI/180;
this._x += Math.cos(angle)*speed;
this._y += Math.sin(angle)*speed;
}


And on the same frame that I have an instance of my ship movie clip, I have the following actions applied:
this.onLoad = function(){
// Array to hold all the bullets that are fired
var bullets = new Array();
}

function spawnBullet(x, y, angle){
// Attach the bullet movie clip to the stage
var depth = _root.getNextHighestDepth();
var b = _root.attachMovie("Bullet", "b_"+depth, depth);

// Position the bullet and set its angle
b._x = x; b._y = y; b._rotation = angle; b.alive = 20;

// The bullets enterFrame event handler
b.onEnterFrame = function(){
// Move the bulltet to it's next destination
var angle = this._rotation*Math.PI/180;
this._x += Math.cos(angle)*20;
this._y += Math.sin(angle)*20;

// If the alive timer reaches zero then remove the bullet
if(this.alive <= 0){
removeMovieClip(this);
}
// Decrease the alive timer each frame
this.alive--;

// Give the bullet's a fade out effect over time
this._alpha -= 5;
}

// Add the bullet to the array
bullets.push(b);
}


If anyway can spot what I'm doing wrong or has any suggestions that could help I would appreciate it greatly. =] You can get my flash file from here.

##### Share on other sites
works fine for me.

win xp with firefox 2.0.0.11

thats fucking cool though, anyway. haha. i tried clicking the ship when it first loaded. ;) thinking it wanted me to "play".

##### Share on other sites
Hmmmm, thats strange. Maybe it's my keyboard, I just changed to use WASD movement controls and it's fine but I'm still having problems with the arrow keys. Unfortunately, I'm creating a two player spacewar clone and need the arrow keys for player two's movements :(

"thats fucking cool though, anyway. haha. i tried clicking the ship when it first loaded. ;) thinking it wanted me to 'play'."

haha thanks. Yeh I edited my post to add the controls in hope no one would get confused ^^

##### Share on other sites
Thanks for testing it musasabi, I just had a ferw friends test it and they also confirmed it works. I guess thats what I get for being so cheap with my keyboard =]

##### Share on other sites
It doesn't work for me; instead it beeps. From your code i cant see any reason why pressing UP+RIGHT+SPACE would work, while preassing UP+LEFT+SPACE would fill up the keyboard buffer. Strange...

##### Share on other sites
Quote:
 Original post by fnmIt doesn't work for me; instead it beeps. From your code i cant see any reason why pressing UP+RIGHT+SPACE would work, while preassing UP+LEFT+SPACE would fill up the keyboard buffer. Strange...

So you have the same problem as me UP+RIGHT+SPACE works but UP+LEFT+SPACE doesnt?
I guess I'm going to have to use WAD and IJL for ship movement as they work fine :S

It is indeed strange. Thanks for testing fnm =]

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633326
• Total Posts
3011373
• ### Who's Online (See full list)

There are no registered users currently online

×