A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Smart HitTest [HELP!!]

  1. #1
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870

    Smart HitTest [HELP!!]

    I made a car game now i wish i could actually lock the car into the track. Any actionscripts to do this?

    Regards,
    tongxn
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  2. #2
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Hey Tongxn,

    Here's some of the code I used for my car game , see if it suits your needs:

    code:

    onClipEvent (enterFrame) {
    // make the car go forward
    if (Key.isDown(Key.UP)) {
    speed += 1;
    }
    // make the car go backwards
    if (Key.isDown(Key.DOWN)) {
    speed -= 1;
    }
    // tells the car to slow down after the speed of 20
    if (Math.abs(speed)>20) {
    speed *= .7;
    }
    // you can change the rotation of the car to your desire
    if (Key.isDown(Key.LEFT)) {
    _rotation -= 7;
    }
    if (Key.isDown(Key.RIGHT)) {
    _rotation += 7;
    }
    // here is where the hittest is for the boundary
    speed *= .90;
    x = Math.sin(+_rotation*(Math.PI/180))*speed;
    y = Math.cos(+_rotation*(Math.PI/180))*speed*-1;
    if (!_root.boundary.hitTest(_x+x, _y+y, true)) {
    _x += x;
    _y += y;
    wall = true;
    } else {
    speed *= -.6;
    }
    }



    That should be it. Make a track with walls, and after selecting the walls (which will be the boundaries) , convert it into a movieclip.

    Give that movieclip an instance name of boundary and run it. Hopefully its what you want.

    Good luck with your game

    ps , we have to hurry and finish your Flashkit Chess game, everyone else seems to be almost done

  3. #3
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870
    Great .. I know but I got school.... sorry...
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

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