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
onClipEvent(load){
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.