# Laser Fires wrong way

**URL:** https://forum.kirupa.com/t/laser-fires-wrong-way/23995
**Category:** Uncategorized
**Created:** [June 25, 2003, 3:01am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995 "2003-06-25T03:01:14Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Theory](https://avatars.discourse-cdn.com/v4/letter/t/f17d59/32.png) [@Theory](https://forum.kirupa.com/u/Theory)
#### Post date: [June 25, 2003, 3:01am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/1 "2003-06-25T03:01:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 3:08am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/2 "2003-06-25T03:08:52Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 3:19am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/3 "2003-06-25T03:19:19Z")

</div>

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:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 3:27am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/4 "2003-06-25T03:27:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 3:33am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/5 "2003-06-25T03:33:39Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 3:36am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/6 "2003-06-25T03:36:38Z")

</div>

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](http://macromedia.com) had an asteroids type of game tutorial on their site somewhere.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 3:51am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/7 "2003-06-25T03:51:04Z")

</div>

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

\*\*\*\* those updates!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 3:54am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/8 "2003-06-25T03:54:18Z")

</div>

AW MAN!!! That sucks! Sorry ☹

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 4:02am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/9 "2003-06-25T04:02:14Z")

</div>

Heh, it’s ok

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 11:34am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/10 "2003-06-25T11:34:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 11:39am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/11 "2003-06-25T11:39:32Z")

</div>

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

Stupid me.

Anyway, here’s the code form MM:

```auto

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;
	}
}

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 11:05pm UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/12 "2003-06-25T23:05:36Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 11:15pm UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/13 "2003-06-25T23:15:02Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 25, 2003, 11:21pm UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/14 "2003-06-25T23:21:17Z")

</div>

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 );  
}

}  
}  
}

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 26, 2003, 4:34am UTC](https://forum.kirupa.com/t/laser-fires-wrong-way/23995/15 "2003-06-26T04:34:12Z")

</div>

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??
