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

i need to make a thing like this, 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… :stuck_out_tongue:

http://www.flashkit.com/tutorials/Games/Building-David_Do-611/index.php

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.

look at my ex.fla… it makes more clear of what i am asking of

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.

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…

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.

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 :slight_smile:

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

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

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

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?

post the FLA?

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

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:

 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. :slight_smile: happy coding :slight_smile:

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…

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?

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.

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.

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.

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

happy to help :rabbit:

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…

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