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.






hi, I ran across your post on the gaia framework and found it interesting. After the read, I clicked this link just browsing through… I have had issues with the limitations of hittest in as3 myself, so I know how frustrating it can be. Anyway, some time ago I found a nice solution to this little issue. The people at labs.boulevart.be took grant skinners solution and ported it to as3. Here is the link, I believe it will prove invaluable to you.
http://labs.boulevart.be/index.php/2007/06/08/skinner-collision-detection-in-as3/
Thanks for the tip (alpha collision detection cool!), I also found one similar in googlecode called CDK here
Hi, how can I fix position of moving object? or if target is not reached, moving object have to come back to base position. or if correct target is not reached but another target2 moving object can stay there. Is possible make it in AS3?
Ah perfect! However, what I were to put a movieClip inside the “mcBall” and wanted that internal movieclip to hit the hole? How would I go about doing that. This is the best one I’ve found… Simple steps and works perfectly.