# Need help with MC collision/laser/hittest something like taht

**URL:** <https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835>\
**Category:** Uncategorized\
**Created:** [August 12, 2004, 10:35pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835 "2004-08-12T22:35:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdjstudios](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@mdjstudios](https://forum.kirupa.com/u/mdjstudios)\
**Post date:** [August 12, 2004, 10:35pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/1 "2004-08-12T22:35:47Z")

</div>

i need to make a thing like this, [http://www.flashkit.com/tutorials/Games/Laser\_Co-Flash\_Ju-81/index.php](http://www.flashkit.com/tutorials/Games/Laser_Co-Flash_Ju-81/index.php)

but i dont want it that fancy though. i have a battlehsip that launches torpedoes. i want the gun of the battleship to aim (not perfectly but not way off so the gn can have 8 directions instead of every direction. [ignore this if u dont know what i mean]) the gun aims near the shark and launches a torpedo.

so basically, i need the battlehsip turret to aim at the shark and duplicate torpedos and have the torpedos launched near the shark. and i need it to move toward the shark. i can take care of the hittest and all the other junk. thanks for your help, sorry it was so long to read… 😛

---

<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:** [August 12, 2004, 11:37pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/2 "2004-08-12T23:37:35Z")

</div>

[http://www.flashkit.com/tutorials/Games/Building-David\_Do-611/index.php](http://www.flashkit.com/tutorials/Games/Building-David_Do-611/index.php)

---

<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:** [August 12, 2004, 11:39pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/3 "2004-08-12T23:39:43Z")

</div>

how does that link help me? thats just another one of those ship games im not trying to make… i just want an mc that duplicates to another mc, and moves toward the shark.

---

<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:** [August 12, 2004, 11:48pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/4 "2004-08-12T23:48:52Z")

</div>

look at my ex.fla… it makes more clear of what i am asking 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:** [August 13, 2004, 6:46am UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/5 "2004-08-13T06:46:07Z")

</div>

I think you can you some \_rotation and if tests to accomplish this. For example, if the shark is at 9oclock position you can check the cannon’s \_rotation and its relative position from the shark. Its hard to explain in words but just do \_rotation manipulations.

---

<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:** [August 13, 2004, 6:49am UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/6 "2004-08-13T06:49:52Z")

</div>

could u give me an example, i dont follow u that well. i COULD, could, make like 5 spaces and i could do a hittest.  
if rootshark is at 1zone,  
play pos of turret 1

if rootshark is at 2zone,  
play pos of turret 2

ect, ect…

---

<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:** [August 14, 2004, 12:27pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/7 "2004-08-14T12:27:03Z")

</div>

here’s a really simple way of doing it. the turret doesn’t won’t go on the N, S, E, W lines or NE, SE… etc… because of the method i used. however, it still works well.

---

<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:** [August 14, 2004, 4:01pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/8 "2004-08-14T16:01:32Z")

</div>

thast exactly what i needed! thanks i raise my hand in gratitude :hugegrin:

althgouh, it is very good and all. i am really looking for the turret to aim at a MC such as MC, “shark” . how would i change for the turret to aim at MC instead of the mouse? i might be able to fool around and figure it out but your help is always lovely 🙂

---

<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:** [August 14, 2004, 4:13pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/9 "2004-08-14T16:13:18Z")

</div>

ohh, wait i got it, i got it! no help needed…

```auto
x = _root.shark._x-this._x;
y = _root.shark._y-this._y;

```

---

<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:** [August 14, 2004, 4:17pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/10 "2004-08-14T16:17:27Z")

</div>

ohh wait… i dont have the hittest part right htouhg.

```auto
onClipEvent (enterFrame) {
	if (_root.shark, hitTest(_root.lazer_main)) {
		_root.shark.play();
		
	}
}

```

what would i replace with \_root.lazer\_main? since the name of the lazer is always changing, i cant have one permanent name, no?

---

<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:** [August 15, 2004, 1:21pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/11 "2004-08-15T13:21:35Z")

</div>

post the FLA?

---

<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:** [August 15, 2004, 1:27pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/12 "2004-08-15T13:27:01Z")

</div>

ok, i think i understand what you are saying. if what you are saying is that you have put the code:

```auto
onClipEvent (enterFrame) {
if (_root.shark, hitTest(_root.lazer_main)) {
_root.shark.play();

}
}

```

# in the shark mc and you are wondering what to use instead of the \_root.lazer\_main movie clip name, then what you have to do is this:

Instead of having the shark do the hitTesting, put the hitTesting on the lazer movie clips. on the main lazer movie clip (lazer\_main) add this code in the onClipEvent(enterFrame) section:

```auto
 if (this != _root.lazer) {
if (this.hitTest(_root.shark)) {
_root.shark.play();
}
}

```

in using this method, we do not have to worry about what the lazers are called. 🙂 happy coding 🙂

---

<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:** [August 15, 2004, 3:13pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/13 "2004-08-15T15:13:28Z")

</div>

thank you! ill try that, thanks a lot for you help… (i renamed lazer\_main to torpedo)  
it wokrs, but… there is one probelm, the torpedo is supposed to explode when it reaches the shark, so when i have this code for the torpedo, it plays the torpedo on the side of the screen instead of the duplicated one…

```auto
onClipEvent (enterFrame) {
	if (this != _root.lazer) { 
	if (this.hitTest(_root.shark) && _root.torpedo.torpedo2.eex==1) { //if it hits the shark and it is rdy to explode
	_root.torpedo.torpedo2.play(); //plays explosion of the original torpedo, not the duplicated one.
		}
	}
}

```

so mainly, how would i play the explosion of the duplicated torpedo?

---

<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:** [August 15, 2004, 4:28pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/14 "2004-08-15T16:28:23Z")

</div>

```auto
onClipEvent (enterFrame) {
if (this != _root.torpedo) { 
if (this.hitTest(_root.shark) && this.eex==1) { //if it hits the shark and it is rdy to explode
this.play(); //plays explosion of the original torpedo, not the duplicated one.
}
}
}

```

I’m not sure, by looking at the code if you fully understand what i meant before, this code should go onto the main torpedo, and when the main torpedo is duplicated, it will also attack the code on the main torpedo to the duplication, therefore when you use ‘this’ it refers to the current torpedo. the first test is important, we can’t have the main torpedo explode and that is why we need to have it test to see whether it is the main or not, and if not it can hitTest().

also, duplications are placed onto the \_root level, not inside the main torpedo.

I don’t full understand what you’re trying to do hear. post the fla and i’ll have a look, that is, if this doesn’t help.

---

<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:** [August 15, 2004, 4:48pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/15 "2004-08-15T16:48:43Z")

</div>

i did put the code on the torpedo, heres the .fla…

i want the duplicated mc to explode, to see what the explosion is edit the torpedo mc.

---

<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:** [August 15, 2004, 5:49pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/16 "2004-08-15T17:49:15Z")

</div>

yeah, you just needed to change it like i said. +/- a couple of little bits i didn’t understand until i had seen the AS.

---

<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:** [August 15, 2004, 6:01pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/17 "2004-08-15T18:01:28Z")

</div>

this is great, this is something ill be saving for future resources! thanks once again!

---

<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:** [August 15, 2004, 6:09pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/18 "2004-08-15T18:09:32Z")

</div>

happy to help 🐇

---

<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:** [August 15, 2004, 6:46pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/19 "2004-08-15T18:46:14Z")

</div>

is there a way where i can make it so that the mc, “t3” which is inside of torpedo2, and torpedo, be the hittest. since the torpedo with the bubbles and the explosion makes the torpedo an easy target to hit, i want to make the mc t3 inside of torpedo, and torpedo2. take a look at the .fla, if the shark touches the bubble or is like 10 pixels away from it, it still will explode. which makes it kind of a hard to avoid if your a big shark…

---

<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:** [August 15, 2004, 7:40pm UTC](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835/20 "2004-08-15T19:40:20Z")

</div>

all you would need to do is change  
if (this.hitTest(\_root.shark) && this.eex==1)  
to  
if (this.torpedo2.t3.hitTest(\_root.shark) && this.eex==1)

and hey presto. there’s a tutorial on kirupa about advanced collision detection, maybe you’ll want to look at that. it can be found here: [http://www.kirupa.com/developer/actionscript/advanced\_collision.htm](http://www.kirupa.com/developer/actionscript/advanced_collision.htm)

[Next page](https://forum.kirupa.com/t/need-help-with-mc-collision-laser-hittest-something-like-taht/60835.md?page=2)
