A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Flash car collisions/hitTest (as2)

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    8

    Flash car collisions/hitTest (as2)

    Well, ive been using flash for a long time but i have to say im no pro at coding. I know some stuff, but not enough for what im trying to do.
    Basically, im making a little car minigame of a car in a city. This is my engine on the car:
    onClipEvent(load)
    {
    speed =0 ;
    }


    onClipEvent (enterFrame) {
    if (Key.isDown(Key.UP)) {
    speed += 0.4;
    }
    if (Key.isDown(Key.DOWN)) {
    speed -= 0.1;
    }
    if (Key.isDown(Key.SPACE)) {
    speed /= 1.15;;
    }

    if (Math.abs(speed)>20) {
    speed *= .7;
    }
    if (Key.isDown(Key.LEFT)) {
    if (speed < 0.5) {
    _rotation -= speed;
    } else {
    _rotation -= 5;
    }
    }
    if (Key.isDown(Key.RIGHT)) {
    if (speed < 0.5) {
    _rotation += speed;
    } else {
    _rotation += 5;
    }
    }
    speed *= .98;
    x = Math.sin(_rotation*(Math.PI/180))*speed;
    y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
    if (!_root.wall.hitTest(_x+x, _y+y, true)) {
    _x += x;
    _y += y;
    } else {
    speed *= -.6;
    }
    }

    Im fine with all of it but the collisions, as the car will only bounce when the registration point of the car collides with 'wall', so it looks all funny and that and the car goes into any thing collable half way then bounces back, and occasionally gets stuck in the wall. Reall annoying. Ive tried fixing it but whenever i remove the hittest parts the car wont even move or turn.

    PLease help me so the wall collides with the car (27.7 x 13) and not the registration, i would be so gratefull.
    Note i need a strong engine which works with curves aswell, and requirs me just putting the code into the car, but if i have to put it into the walls/frame i suppose its okay, but theres no way im going through every single building and that.

    Also, it would be cool if:
    -You could give me an engine where when reversing the steering is reversed (like irl)
    -The car doesnt bounce backwards when driving at a wall at an angle, but slides against it (like irl)

    Thanks. (btw, ive tried sites like emanuale fernando and that but they never work).

    -SM

  2. #2
    Junior Member
    Join Date
    Sep 2010
    Posts
    8
    Hey guys, i really need this so if i got a reply id be over the moon - i dont really appreciate having the next few threads get replys.

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    8
    please stop making me have to double post an bump, please

  4. #4
    Junior Member
    Join Date
    Sep 2010
    Posts
    8
    guys, im getting really hacked off now.

  5. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    8
    COME ON, this site sucks if you can wait this long without a reply. its been a whole week.

  6. #6
    Junior Member
    Join Date
    Sep 2010
    Posts
    8
    SERIOUSLY GUYS! why the hell is this one of the first forums on google if you cant even get a reply after a week and 100 views?

  7. #7
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Look here and correct your collision detection.

    http://troygilbert.com/2007/06/pixel...actionscript3/
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  8. #8
    Junior Member
    Join Date
    Sep 2010
    Posts
    8
    That doesnt help since its AS3 and not for car movement.

  9. #9
    Junior Member
    Join Date
    Sep 2010
    Posts
    8
    Why do i even bother? this site is crap and has been no help whatsoever. Good bye.

  10. #10
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    And that is why no one answered your question.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

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