A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: hitTest on rotated movieclip

  1. #1
    Join Date
    Feb 2004

    hitTest on rotated movieclip

    I have a car which goes round a track and I'm using hitTest to bounce it back onto the track when it goes off.

    This has already taken a lot of movieclips placed round the edge of the track and is not very accurate.

    What would make it more accurate is if the car's bounding box rotated with the car rather than always being a box x*y.

    It would be a lot more accurate if I could rotate the walls at the side of the track aswell.

    Is this possible or am I stuck with vertical*horizontal boxes?

  2. #2
    avatar free
    Join Date
    Jul 2002
    Well I'm still having nightmares about this rotated rectangles...

    There is another form of the hitTest() function, which takes a point to test and a MovieClip to test it against. But it tests what is solid in the MovieClip, not just it's bounding box. You could work out the corners of the car using maths and trig to get the points. Then hitTest against the MovieClip containing the track walls. Not only does this mean the track can be put on a single MovieClip, but you can get pretty much "pixel perfect" hitTesting.

    Of course the other alternative is to use pure maths. But the hitTest way is much easier for this type of game. Check out The elusive hitTest explained thread for more gorry details of the hitTest function.
    flash racer blog - advanced arcade racer development blog

  3. #3
    Join Date
    Feb 2004
    I've been through the hitTest sticky and it was full of threads of people like me hoping that there was a nice simple hitTest(shapeA, shapeB)

    My first instinct was to do the 4 corner method in my car movieclip but you then have the problem of the coordinates being relative to the movieclip rather than the stage.

    Then I thought I'd work out the corners of the car from it's (x,y) it's (width,height) and it's rotation. I'm pretty sure that is the best way to do it but I have settled with a simpler less accurate method for now (see attached .fla for details).

    Brief explanation:
    I've done a seperate hitTest for 5pixels away from the centre of the car in each direction. The car is moved back onto the track, slowed down and rotated onto the track, clockwise for the outside and anticlockwise for the inside.

    I'm quite happy with my progress but if anyone would like to tell me how to work out the exact corners of the car I'd be very grateful.

    BTW, see if you can tell which track it is.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center