Old school racing (TopGear, Lotus) game track algorithm

Started by
10 comments, last by Ravyne 11 years, 9 months ago
Hi, I'm working on a old school racing game made in JavaScript. I use sine waves packets (added sines with different wave lengths, phase and amplitude) for the track's shape. However, It doesn't feel entirely right. You can look at it here (please use Chrome, Ie9 or Firefox), or else, it will be slow.
http://www.anticulture.net/Games/RandomRacing/
I believe it looks good, but I would like to know what are the true math algorithm that was used in old games like rad racer, topgear (1, 2, 3000) and lotus turbo challenge. Thank you!
[quote]Firemen get paid even if there's no fire, and that's a good thing -me[/quote]
Advertisement
Actually that's pretty good, and all that was really done back in the day was handle the interrupt that would occur at the beginning of each scanline and scroll it by a given amount - very similar to what you're doing.

Realize that
a) It will never feel completely right done this way
b) There are times when you want to just have it go right or left for a while to give a sense that the track is going in a complete circle. Right now it just feels like it is an inifinitely (generally) straight track.

It feels really nice, and looks awesome, but you almost need to overdo a turn here or there so that the track feels like it is connected in a loop - unless of course the track isn't connected in a loop.

You may experiment with shifting the scene up or down a bit too... perhaps it would feel better if it wasn't so exactly behind the player.

All in all it feels good... I think you are closer than you realize. Just needs some minor tweaking!
Thanks a lot for the encouragements :smile.png . Yes, I think it looks good, but the problem I see is the curves. Since I use "added sine waves", each wave has a full cycle, which means that whenever you turn right, you will immediately turn left (because of the wave's rarefaction). I suspect old school games didn't use sine waves, but some other kind of math function (which I don't know about). That is my main concern.
[quote]Firemen get paid even if there's no fire, and that's a good thing -me[/quote]
Say you want to simulate turning 90 degrees in one direction. All you would do is use a sine wave of the appropriate length, from, say, 0 radians to pi/2 or even pi/4 for your horizontal offsets. While driving, the sine wave should gradually go from having no amplitude to much amplitude to go into the curve. Hold it at that amplitude for however long the turn is, and finally gradually interpolate back down to no amplitude to get out of the curve.
Alright, I will do that. I guess sines can be used with some tweaking.
Right now, what I do is extremely simple. The track itself is a math function of some sines, and I never have to interpolate anything. Some parts of the wave are cancelled by other wave, and some interference patterns are created. Playing my game is basically like watching a function on a Ti-83, but with a moving 3Dish perspective.
[quote]Firemen get paid even if there's no fire, and that's a good thing -me[/quote]
Just keep in mind there is not necessarily just one way to do this. What you've got going on would be perfect if, say, the tracks travel for a long distance and aren't meant to be looped. Say a race across the countryside or something.

If you really want to be closer to top gear, you really can't beat just watching a couple youtube videos and figuring out how to emulate what you see. Maybe you don't do it like they did exactly... but that doesn't really matter! For instance... I could be mistaken, but it seems when there are multiple road curves on screen, that there is always a hill where the second curve is... Sometimes overcoming technical difficulties can produce unexpected, nice, extra "features"!

Anyway I like yours. I hope to not miss your post when you make more progress!
Thanks! :), I will keep you informed.
[quote]Firemen get paid even if there's no fire, and that's a good thing -me[/quote]
Look into splines. 2D Splines will give you a way to define both closed and open circuits on generally-flat ground, 3D splines will allow you to also define hills and valleys. Once you have splines, and can evaluate them at a given point, cast a ray for each horizontal line to see where it intersects the spline to get the distance (used to scale the roadway). You should also be able to use the control points store track data (e.g. this section of road is a bridge, this section is the finish line, etc).

I'm not certain how they'd have done it in the really olden days though -- I'd guess run-length-encoded deltas, possibly with interpolated values in-between.

throw table_exception("(? ???)? ? ???");

It seems I'm now (in the new version of my game) trying to emulate splines using sine waves. Thanks.

edit: I dopped "spline emulation through sine wave" and now I use perlin noise with a lot of smoothing, then I normalize the function to expand the minimum and maximum to a desired range. I get better results with that.
[quote]Firemen get paid even if there's no fire, and that's a good thing -me[/quote]
Just to keep interested people updated, I finished the new version of my game (requires a modern browser (Chrome, Firefox, Ie9))
http://www.anticulture.net/Games/ajaxracer/
[quote]Firemen get paid even if there's no fire, and that's a good thing -me[/quote]

This topic is closed to new replies.

Advertisement