A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: I want to make a car drive round a race track

  1. #1
    Junior Member
    Join Date
    Oct 2003
    Location
    -
    Posts
    9

    I want to make a car drive round a race track

    Hi
    I am doing an assignment and I have to make a car drive around a race track. I want you to be able to control the car with the keyboard. I have this code:
    onClipEvent(enterFrame) {
    speed = 10;

    if (key.isdown(key.UP)) {
    _y-= speed;
    }

    if (key.isdown(key.DOWN)) {
    _y+= speed;
    }

    if (key.isdown(key.LEFT)) {
    _x-= speed;
    }

    if (key.isdown(key.RIGHT)) {
    _x+= speed;
    }
    }

    But my car doesn't turn. It like slides and it stays the same way. I need a script that i can type in that will enable me to make the car move properly and change direction.
    PLEASE HELP ME!

    Last edited by funky_sponge; 10-03-2003 at 09:12 AM.

  2. #2
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    hey there,you shouldn´t just change _x of the car when pressing left or right,instead you should chnage the rotation ( _rotation )
    also press the search button and have a look for threads having to do with car motion,there are plenty of sources/threads on the board

  3. #3
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Heres a script with rotation I found here earlier AND collision detection if you need it.

    Code:
    onClipEvent (enterFrame) {
    if (Key.isDown(Key.UP)) {
    speed = speed + 1;
    }
    if (Key.isDown(Key.DOWN)) {
    speed = speed - 1;
    }
    if (Math.abs(speed) > 20) {
    speed = speed * 0.7;
    }
    if (Key.isDown(Key.LEFT)) {
    _rotation = (_rotation - 15);
    }
    if (Key.isDown(Key.RIGHT)) {
    _rotation = (_rotation + 15);
    }
    speed = speed * 0.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 + x);
    _y = (_y + y);
    } else {
    speed = speed * -0.6;
    }
    }

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  4. #4
    Wannabe
    Join Date
    Jun 2003
    Location
    depends on my schedule for the day
    Posts
    155
    pelle I thank you, finally that code is out and being used.

    rocket science for script kiddies

    you can find the original in the
    post your code snippets for mx 2004
    thread

    looks like youll have to, the code above doesnt work lol

  5. #5
    Junior Member
    Join Date
    Oct 2003
    Location
    -
    Posts
    9
    Originally posted by enceenoman
    pelle I thank you, finally that code is out and being used.

    rocket science for script kiddies

    you can find the original in the
    post your code snippets for mx 2004
    thread

    looks like youll have to, the code above doesnt work lol
    I don't get what you mean 'encee'. I know that the code doesn;t work but i don't get where to go to get the code? Could you please give me a link to the page or a code to help me. I would appreciate it if you could help me!
    Thanks
    Steph

  6. #6
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    I dont understand. The code I posted works just fine, even the collision detection.

    I dont know who wrote it though, I have a couple of similar scripts found on different forums.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  7. #7
    Senior Member Skinny_T's Avatar
    Join Date
    Sep 2003
    Location
    Australia
    Posts
    149
    Yeah, the code does work fine. I have another question, when I run it and start driving around the image doesnt look really smooth. How do I fix that? Heres the fla.
    Attached Files Attached Files

  8. #8
    Junior Member
    Join Date
    Aug 2003
    Location
    Washington
    Posts
    18
    If your fla is accurate, you're running the movie at 12 fps, if you want to make it faster just increase your fps, I'd say to about 25 ish. Nice Harvest Moon sprite btw
    Its me sitniz, and I'm cunphuzed.

  9. #9
    Senior Member Skinny_T's Avatar
    Join Date
    Sep 2003
    Location
    Australia
    Posts
    149
    thanks. it still doesnt look smooth though

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