A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: help with collision in racing game

  1. #1
    Senior Member
    Join Date
    Dec 2005
    Posts
    135

    help with collision in racing game

    hi,

    im making a simple top down racer - ususal format the car is controlled by keys and drives around a track. the track is a MC called "collision" when the car hits the side of the track i want a hit test to occour and the car to bounce back. I have the following code but for some reason cant get the car to hit the walls?

    id really apprechiate any help on this?

    if (_root.collision.hitTest(this._x, this._y, true)) {
    //if current position is inside the level_mc
    _y += ySpeed*1.1;
    //move back to previous position(plus a little)
    _x -= xSpeed*1.1;
    speed = -(speed*bounce);
    //reverse speed, and lose a little speed based on bounce
    }

    thanks

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Your code doesnt make much sense. It only applies to situation of car being on the track and you add ySpeed but substract xSpeed. I suspect you should use if..else statement:

    if (_root.collision.hitTest(this._x, this._y, true)) {
    //move normally
    }else{
    //bounce back
    }

  3. #3
    Senior Member
    Join Date
    Dec 2005
    Posts
    135
    sorry i cant seem to get my head around what is wrong. If i attach the file is there any chance you could have a quick look? its strange because the car does bounce off the walls now but only sometimes.?

  4. #4
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    An attached fla is the best help... if people bother downloading it that is . Always start with posting the code, if that doesn't help, attach the fla.

  5. #5
    Senior Member
    Join Date
    Dec 2005
    Posts
    135
    ok its 99% working now thanks,

    the only problem is the hit test works when the front or rear of the car hits the wall. but you can hit the wall side on. (as you can skid) and go straight through it.

    ANy ideas how i could wack a hit test on the side of the car as well?

    if (_root.collision.hitTest(this._x, this._y, true)) {
    //if current position is inside the level_mc
    _y += ySpeed*1.1;
    //move back to previous position(plus a little)
    _x -= xSpeed*1.1;
    speed = -(speed*bounce);
    //reverse speed, and lose a little speed based on bounce
    }

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