Thread: Simple driving game

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001

    Simple driving game

    After many unsuccessful attempts at doing a simple perspective racing game I have finally figured out the algo.

    Essentially you have a road in 3D vertexes. You only need as many vertexes to make the road look like it stretches into the distance.

    The vertex z components never change for these and neither do the y. Only the x component changes.

    This essentially splits the road into horizontal sections.

    Ok what about curves? Well I thought about this forever and came up with this.

    For any of you that have done the fire effect or any kind of texture cascading you will understand this. First you need to setup a loop that transfers one segment of road offset on x to the next segment. Basically you are handing the offset value off to the next segment.

    The offset value is to simulate curves. After all if we are in 3D and all vertexes have the same x value....the road will be perfectly straight. The only thing that would cause a bend is if one vertex was offset on x some distance from the previous vertex x. And since everything scrolls from max z to min z (for forward movement) all you have to do is change the first vertex or the most distant one's offset. This will be transferred all the way down the chain.

    So how to you store the road data?

    • Neutral offset on x means you will have a straight road.
    • Negative offset means the road is curving to the left, or recovering from a right turn
    • Positive offset means the road is curving to the right, or recovering from a left turn
    So in your editor for the game you simply allow the user to add in curves. All you must do is decide on a sampling size and find out how much each vertex is offset from the center of the curve.

    So one section of road might look like this in memory.

    0 --> we start here on straight road
    0 --> straight
    0 --> straight
    0 --> straight
    0 --> straight
    .1 --> road is curving to the right a bit
    .4 --> road is curving more to the right
    .7 --> road is prob at right side of screen
    -.4 --> road is coming back to the left
    -.1 --> road is still moving left
    0 --> road is straight again

    This would be a straight away with a sharp curve to the right followed by another straightaway.

    You will move through the track data at player.speed/some_constant.

    for (int i=0;i<num_road_segs-1;i++)

    I had to share that with the board because it was so simple it eluded me for years.

    I will try to post a simple demo here soon of like Indy 500 track or something.

    Of course with this method you won't be able to turn around....for that you need pure 3D.

    If you wanted to add hills....simply change the y offset of the top vertex and transfer that y offset down the chain. The hill will gradually come to you. Don't alter the top vertex y though or you will get weird looking stuff. Only alter (1+top)->end of list.

    Also one caveat of the algo is that you must move the same amount in the opposite direction to come out of a hill or curve. This will return all vertexes to their original positions. If you continue to move away from center...the road will go off screen and cause major issues.
    Last edited by VirtualAce; 07-01-2004 at 12:01 PM.

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Plano, Texas, United States
    Thankyou for watching another dissertation by Bubba. Any questions may be forwared to him at this address:

    Maybe we should just start posting Bubba's dissertations on the Tutorials page.
    My Website

    "Circular logic is good because it is."

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Seattle, WA
    Or maybe he could write some tutorials and submit them to this site? Hmmm?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Actually its not a dissertation, it's an algo I'm going to try. Maybe it will help those trying to make a racing game but don't know where to start.

    I just don't have a demo yet so no screenshots.

    But we do need tutorials on effects and algos like these: Fire, Water, Particle Effects, Billboards, clouds, etc., etc.

    All of this is extremely useful in game dev. Perhaps some of us could contribute to the tutorial board on these topics.
    Last edited by VirtualAce; 07-01-2004 at 11:43 PM.

  5. #5
    Registered /usr
    Join Date
    Aug 2001
    Newport, South Wales, UK
    What sort of racing game are we talking about here? Outrun, or something hardware accelerated?

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    This is for a simple 2D racing game that appears to be 3D. It is a first person driving algo but it does not allow you to turn around and go the opposite direction.

    So yes, I think Outrun would probably fit into this category. With good graphics and hardware acceleration I think that someone could come up with a very good arcade racer using this algo.

    Of course if you want full 3D then you will have to design a 3D engine to handle it.

    Just wanted to show how it can be done.

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Working on a new algo. This one does not work as planned.

    I wonder how they did it old school like on the Atari 2600. There is no way they were doing pure 3D on that 26K system.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a simple Windows game
    By ejohns85 in forum C Programming
    Replies: 1
    Last Post: 05-22-2009, 12:46 PM
  2. Simple game over network
    By Tommo in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-12-2007, 03:07 PM
  3. Simple Game Engine Programming
    By AoA in forum Tech Board
    Replies: 1
    Last Post: 05-26-2006, 12:50 AM
  4. Reading game port with a simple compiler like BuilderX?
    By MaxxMan-X in forum Game Programming
    Replies: 7
    Last Post: 02-27-2005, 11:15 AM
  5. My Memory Game
    By jazy921 in forum C Programming
    Replies: 0
    Last Post: 05-05-2003, 05:13 PM