Laser Fires wrong way

Attached is a picture of the lasers (the yellow) coming out of a spaceship. The spaceship moves around like the asteroids spaceship, but the laser comes out to the side, can anyone tell me the correct actionscript to have the laser come out of the front, even as you turn? That would be terrific, thank you.

I will attach actionscript I had if requested.

I am not game programmer nor do I have Flash 6 so I can’t help much, but heres a point in the right direction…

Whatever clip you are duplicating… put it inside your spaceship clip. That way it will be launched correct no matter what the ships rotation is. You will have to adjust the targeting to duplicate the clip and stuff of course.

Well, the laser clip will be hitting other targets, so It would be kind of pointless, seeing as how the laser would be part of the spaceship.

Thanks though. :cyclops:

If it hits other targets and uses hitTest then change the targeting of the hitTest :-\

Ill probably do that, but I want to see if people have the Asteroids actionscript… plus, If something hits the lasers, it should die, and if something hits the spaceship, YOU should die, so… If i put them in the same clip, wouldnt that just have one or the other?

See, theres is where my lack of game programming gets in the way.

The way I was thinking is your enemies each run the hitTest() to check for the laser clip inside the spaceship clip, and another hitTest() to check if the spaceship actually hits it.

But I have no idea how to go about doing that due to my lack of game coding experience.

But now that I think of it, I think macromedia.com had an asteroids type of game tutorial on their site somewhere.

Dang, I found that tutorial, but I need the Flash 5 version :angry:

**** those updates!

AW MAN!!! That sucks! Sorry :frowning:

Heh, it’s ok

try to substract 90 degrees from the final code, that should work. (or 1/2*Math.PI in radians)

But wait… you have Flash 5. Ow wait, i get it.

Stupid me.

Anyway, here’s the code form MM:


onClipEvent (load) {
	// declare and set initial variables
	thrust = 1;
	decay = .97;
	maxSpeed = 15;
}
onClipEvent (enterFrame) {
	// rotate right or left
	if (Key.isDown(Key.RIGHT)) {
		_rotation += 10;
	}
	if (Key.isDown(Key.LEFT)) {
		_rotation -= 10;
	}
	// 
	// 
	if (Key.isDown(Key.UP)) {
		// calculate speed and trajectory based on rotation
		xSpeed += thrust*Math.sin(_rotation*(Math.PI/180));
		ySpeed += thrust*Math.cos(_rotation*(Math.PI/180));
		flames._visible = 1;
	} else {
		// deccelerate when Up Arrow key is released
		xSpeed *= decay;
		ySpeed *= decay;
		flames._visible = 0;
	}
	// 
	// maintain speed limit
	speed = Math.sqrt((xSpeed*xSpeed)+(ySpeed*ySpeed));
	if (speed>maxSpeed) {
		xSpeed *= maxSpeed/speed;
		ySpeed *= maxSpeed/speed;
	}
	// 
	// move beetle based on calculations above
	_y -= ySpeed;
	_x += xSpeed;
	// 
	// loop to opposite side of the stage when the beetle travels off-screen
	if (_y<0) {
		_y = 232;
	}
	if (_y>232) {
		_y = 0;
	}
	if (_x<0) {
		_x = 465;
	}
	if (_x>465) {
		_x = 0;
	}
}

Do i add that in to the laser’s script, or the spaceships? cause I put it on the spaceships, and the laser doesnt stay in front of the spaceship, it just rotates kind of.

I added it to the spaceship, and the same thing happens, although, the movement is a lot more like asteroids, and the thrust shows up only when UP is pressed. Where did you get this script?

Here is the script I have for the laser… I took it off another game I made, so I know it’s not right. But I need the right one :geek:

onClipEvent (load) {

laserMoveSpeed=30;
this._x=_root.spaceship._x+30;
this._y=_root.spaceship._y;

}

onClipEvent (enterFrame) {
if (this._name<>“laser”){
this._x+=laserMoveSpeed;
if (this._x>600){
this.removeMovieClip();
}

for (i=1; i<=_root.numEnemy; i++){
if (this.hitTest( _root[“enemy”+i])){
_root.score+=100;
_root[“enemy”+i].gotoAndPlay( 2 );
}

}
}
}

Alright, does anyone have the code for the asteroids game, on the macromedia site, but for flash 5? I have all the rotations, and the movements of the craft down, but, I just dont have the code for the laser. I took one off my other game, in which the laser moves off to the left of the screen. Can anyone please help??