Actionscript HITTEST problem with diagonals in minigolf game

Hi all, this is my first post on this forum, I’ve been looking for a good flash-forum for a while and I think I found it :slight_smile:

Now on to the problem:

I’m trying to design a minigolf game to get better at actionscripting.
Shooting the ball works depending on mouse-angle and distance from the ball.
Bounces work on horizontal and vertical walls using hittest…

…but there is a problem with diagonal walls (45 degrees)…

hittest works on the bounding box of the vertical wall, but I don’t want it to do that, I want it to work on the wall itself…

Is there any way to detect collisions on a diagonal and NOT on it’s bounding box, without going into pixel-detection?

See the attached images to get the idea.

Thanx in advance!

you should read the MX help doc:


Flash Player 5.


myMovieClip.hitTest(x, y, shapeFlag)


x The coordinate of the hit area on the Stage.

y The coordinate of the hit area on the Stage.

The and coordinates are defined in the global coordinate space.

target The target path of the hit area that may intersect or overlap with the instance specified by MovieClip. The target usually represents a button or text-entry field.

shapeFlag A Boolean value specifying whether to evaluate the entire shape of the specified instance (true), or just the bounding box (false). This parameter can only be specified if the hit area is identified using x and y coordinate parameters.




Therefore, use the shapeFlag value (true)



edit: I just re-read the thingy myself and noticed it only work for hitTest(x,y,flag) and not hitTest(target)… dunno how you do it for shapes against shapes…

Yeah…I read that thing from top to bottom, but couldn’t find a solution. Google couldn’t help me out either and all the major flash-tutorial/source-sites also didn’t get me any further…so this is kinda my last hope…

thnx for the reply anywayz
The problem with the built in hitTest in flash is that it only detects either bounding boxes or points. The technique in the link will show you how to develop a better hitTest. I dont quite understand it…but its a good read.

Did anyone ever get that to work? I tried exactly that, creating a vertical bar and then rotating it. When i click on the mc it looks like the bounding box is in fact just as big as the bar itself, but testing it in the game it shows that the bounding box is in fact a square with the bar as a diagonal in it.

Also aaslos, did you make progress with your game? Did you find a solution? I’d be glad to know, because i am tackling the exact same problem and don’t seem to find an economic solution.

hey is there a turtorial anywhere for making a minigolf game… I understand the hittest stuff but i dun really understand how to make one of those things where the u click, hold, choose ur angle and fire the ball. I not really sure how thats done… Is it whereever the ball is it releases a mc of the club that is used to hit it… i not sure…
help appreciated

Have a look at this game:

it will help you with the basic functions you are looking for.

thanks i needed that too

No matter how you rotate a movieClip… It will continue to have a bounding box equal to it’s far left point, far top point, far right point and far down point… Unfortunately…

What I would suggest is making your walls into a movieClip and then using a system of 4-8 points around your ball. Like this figure:

Using this method of 8 points, you can get a decent location on your ball. This requires more hitTesting… But there are methods in which you can simplify the amount of tests you do at any time…

For instance… If the ball is travelling to the north direction… you wouldn’t have to check the points that are behind the ball, because they won’t hit anything before the other points will.

These are just a couple of ideas for you guys to ponder about… I used this method in a breakout game I created and I could carry over 100 blocks on screen and hitTest a ball perfectly… :smiley: Too bad I can’t find the .fla anywhere across my mutliple computers… :sigh: