Be a Supporter!

[as3] Hittest On Mc Within Mc

  • 1,127 Views
  • 4 Replies
New Topic Respond to this Topic
snorte
snorte
  • Member since: Mar. 11, 2009
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
[as3] Hittest On Mc Within Mc 2010-03-23 14:50:56 Reply

I'm having a problem getting a movieclip within another movieclip to react on a hitTest.
In this case the outer MC is a character, within that character is a weapon. I want an enemy MC to react on the weapon only, and not the main MC.

I have no problem solving this with a less effective method, but I can't imagine the method I'm asking for doesn't exist.

Thanks in advance
Alexander

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to [as3] Hittest On Mc Within Mc 2010-03-23 14:54:02 Reply

So basically, there's A character MC, inside of that, a weapon MC. Then on the main timeline there's an enemy MC. You want to check collision between enemy MC and weapon MC.

It should be simple, it'd help if you posted the code you're currently using, but this should suffice:

if(enemyMC.hitTestObject(characterMC.weaponMC)){
//Collision
}
snorte
snorte
  • Member since: Mar. 11, 2009
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to [as3] Hittest On Mc Within Mc 2010-03-23 15:05:33 Reply

At 3/23/10 02:54 PM, 4urentertainment wrote: if(enemyMC.hitTestObject(characterMC.wea ponMC)){
//Collision
}

Thanks for the quick reply. However, by using that method, which I've already tried numbers of different variations of, I get this Output error "TypeError: Error #2007: Parameter hitTestObject must be non-null."

Any ideas?^^

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to [as3] Hittest On Mc Within Mc 2010-03-23 16:08:08 Reply

At 3/23/10 03:05 PM, snorte wrote:
At 3/23/10 02:54 PM, 4urentertainment wrote: if(enemyMC.hitTestObject(characterMC.wea ponMC)){
//Collision
}
Thanks for the quick reply. However, by using that method, which I've already tried numbers of different variations of, I get this Output error "TypeError: Error #2007: Parameter hitTestObject must be non-null."

Any ideas?^^

It seems as though one of the objects is not there, or can't be referenced from where you have the code. Is the code on the main timeline?

snorte
snorte
  • Member since: Mar. 11, 2009
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to [as3] Hittest On Mc Within Mc 2010-03-23 16:31:52 Reply

At 3/23/10 04:08 PM, 4urentertainment wrote: It seems as though one of the objects is not there, or can't be referenced from where you have the code. Is the code on the main timeline?

Yes, the code is on the main timeline. But now I get the error "#1010: A term is undefined and has no properties."

I made a mistake. I didn't realize that "weaponMC" was nested in not 1, but 2 movieclips.
So it's "characterMC > randomMC > weaponMC". I made the necessary adjustments to the code and got the error shown above ^^

So the code now shows:

if(enemyMC.hitTestObject(characterMC.randomMC.weaponMC)) {
   
}