A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Collision Problem (racing game)

  1. #1
    Junior Member
    Join Date
    Mar 2006
    Posts
    24

    Collision Problem (racing game)

    Hey, I'm new here, and I'm also fairly new to flash, I am having a problem with making collision boundries in flash, and I want you help... here is what I have so far... The instance "land" is the boundry, this script is on the car.

    onClipEvent (enterFrame) {
    //This code will advance the car forward.
    if (Key.isDown(Key.UP)) {
    speed += .5;
    }
    // This will make the car go backwards
    if (Key.isDown(Key.DOWN)) {
    speed -= .5;
    }
    //The car will start to slow down after the speed of 10
    if (Math.abs(speed)>5) {
    speed *= .5;
    }
    // This will change the angle of the car
    if (Key.isDown(Key.LEFT)) {
    _rotation -= 4;
    }
    if (Key.isDown(Key.RIGHT)) {
    _rotation += 4;
    }
    // here is where the hittest is for the boundary
    speed *= .98;
    x = Math.sin(_rotation*(Math.PI/180))*speed;
    y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
    if (!_root.land.hitTest(_x+x, _y+y, true)) {
    _x += x;
    _y += y;
    } else {
    speed *= -.6;
    }
    }

    My problem is, when I hit the boundry straight on, It works, but when I rotate on the boundry, I can go right through it with the car. I want a way so that the car can't rotate on the boundry, or if I can't do that, a way that even if the car does rotate, it can't go through the wall.

  2. #2
    Junior Member
    Join Date
    Mar 2006
    Posts
    24
    Please????

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    why not post yoru fla here so we can have a look..is the boundary an an angle or is it horizontal or vertical?
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    Junior Member
    Join Date
    Mar 2006
    Posts
    24
    The boundry is both vertical and horizotal... it a square on the inside of the track... I will upload the FLA soon...

  5. #5
    Junior Member
    Join Date
    Mar 2006
    Posts
    24
    ok.. her is the link.... http://media.putfile.com/Racing-Game69

    The boundry is what is keeping your from were the logo is... see how the "car" is over hanging it?

  6. #6
    Senior Member corky§urprise's Avatar
    Join Date
    Jun 2005
    Posts
    346
    Actually, no, it barley hangs over it at all. That isnt a collision problem, your just being fussy

  7. #7
    Junior Member
    Join Date
    Mar 2006
    Posts
    24
    come on, it is for school... I want it perfect... isn't there a way so that it stops right were the black starts?

  8. #8
    Senior Member corky§urprise's Avatar
    Join Date
    Jun 2005
    Posts
    346
    Post the FLA then.

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