AS3 Shape Based HitTest / Collision Detection

During one of my flash game development project, I soon found out that I need to use some kind shape based hit test. Yes, basically – in older days of hittest, this can be accomplish with either an insane amount of mini invisible movieclip stacked around the shape of the object, or they do it using some mathematically formula. This is because, the function hitTest doesn’t work exactly like the shape of the movieclip but, takes the entire movieclip as whole.

Well, this tutorial isn’t about the two method above but, a way simpler method to do collision detection based on shape.

Take a good look at the sample flash below in action.

In situation like this , we use the function called hitTestPoint which requires 3 parameters. First two parameter signifies the point of x and y the target movieclip you want to act as your first point of contact.

If you are making an object like a ball rolling towards the hole then, your target registration point for the movieclip ball should be the center and at the very bottom of the movieclip. The third parameter will be whether exact shape comparison between both target is required and it is a boolean. For our case it is set to true.

Download the fla code here and have it a go.

Download Here