Skip to main content
Inspiring
October 30, 2015
Answered

hitTestObject as a Child

  • October 30, 2015
  • 5 replies
  • 773 views

I am creating a real time fighting game, and on the stage I have two boundary boxes (MovieClips). There are also two character MovieClips, each added as a child to their respective boundary box through the timeline code. In each of these MovieClips, there is a hitbox, which, for certain animations, has it's .visible property set to false. What I need is for a boundary box to detect when it is being hit by a visible hitbox, and then run the damage function based on a variable which is set in the animation.

How do I do that?

Every time I try hitTestObject(MovieClip(parent).box.char.hit) it tells me that it doesn't exist.

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer nezarov

then you've to active the .hitTestObject method only during the attack because in all cases if the character box visibility is false or true it will be damaged when the touch happening.

5 replies

Inspiring
October 30, 2015

- set the hit box visible to true and use alpha = 0 instead.

- hit test:

if(box1Name.hitTestObject(box2Name))

{

// run the damage function

}

mcdermittAuthor
Inspiring
October 30, 2015

But then if the box touches the enemy during a non-attack animation, it will be damaged.

If I remove the frames containing the invisible hitbox, I get a lot of errors saying it can't find the object.

The check for the boundary hitting the hitbox is run every frame through an event listener.

nezarovCorrect answer
Inspiring
October 30, 2015

then you've to active the .hitTestObject method only during the attack because in all cases if the character box visibility is false or true it will be damaged when the touch happening.