Car Templates 4
|Top Previous Next|
The 4th installment of the Car Template brings us a customizable, template-based water effect and (most of all) implements one of your requests: racing track texture detection, which allows us to simulate ice, water, grass and oil in our racing tracks. In fact, I'm not tracking the actual color of the terrain texture, but the color of another bitmap, which was generated using the terrain texture as a base.
Let's start by seeing the customizable options of the water effect, which was added to the t_car_props files. Open the level in Wed, and then click the "Resources" tab, open "script files" and then right click "t_car_props.h" and choose "Customize" - you will see the following window:
We're only interested in the "Water Effects" tab; we've discussed all the other tabs in the previous workshop. As you can see, we can set the speed of the water on the X and Y axis, its ripple strength and scale, as well as its RGB color. The default values work fine, but feel free to play with them if you want to. Oh, and since we're here, the water code will detect if you've got A7 commercial or higher and a decent 3D card; if it can't find them, it will default to a more simple water effect.
I'm really excited to tell you about this month's template goodies; in fact, I've only added the water code because I needed some water in my level to test the race tracking code. What is that? It's a snippet that tracks the color of a texture and tells player's car to react differently, depending on the surface: a grassy area will slow down player's car (Go Green!) an oily area will make the player lose control of the car, the icy area will be more bouncy and the water areas will play a river-like sound and will generate water particle effects close to the wheels.
Let's see what can be customized first; once again you'll have to open the "Resources" tab, and then open the scripts, right click t_car_tracks.h and then choose "Customize".
The "Tracked colors" section sets the colors on the color map bitmap that will be used for the ice, the grass, the oil and the water. I chose pure white, green, black and blue, but you can choose any other color; just make sure that the rest of your color map bitmap has a different color - otherwise, the player won't be able to drive normally.
The "Water particles" section sets the size, the transparency and the fading out time for the water splash particles that are generated while player's wheels touch the water. Finally, the "External resources" section sets the name of the color map bitmap, the water particles bitmap and the looping "player's car is in the water" sound.
I think you're either anxious to see it or troubled about this color map bitmap I've been mentioning. Here's how I have created it:
- First of all, I have exported the skin for the terrain using Med;
- Then, I have painted all the areas that are supposed to represent grass, water, oil and ice on the bitmap using Paint Shop Pro (hint - use the "Magic Wand" tool of your graphics editing application).
Do you see the green areas? These are the areas where player's car will slow down (only if it drives over them, of course). The same thing goes for the blue (water), white (ice) and black (oil) areas. The rest of the skin was painted using a neutral color; I chose red, but you can use any other color, provided that it isn't identical with one of the colors set in the "Customize" panel. Oh, and when you are done with it, make sure to save the file as colormap.tga - this is your color map bitmap.
This level wasn't created as a standard racing track, so the track / grass areas, etc aren't clearly separated. I chose to paint the skin of the terrain as well; this has made the level look much uglier, but it helps the driver tell when he / she has crossed one of the color borders.
I could have used a second terrain skin for the color map bitmap, but this would have caused trouble if you would have wanted to apply all sorts of shaders to it. Just keep the car on the road, avoiding the green areas and you'll be safe.
Get in the water and you'll hear the water sound and see the water splash particles. Don't laugh at my poor blue paint job - I'm only a programmer, so it has taken me a lot of time to do it.
The ice prepares the player for the oily areas...
If you see oil, try to avoid it at all costs - you're going to have a hard time trying to keep the car on the track.
The wheels have individual sensors, so if (let's say) only one of player's wheels touches the grass, the car will be slowed down, but not too much. On the other hand, if all the wheels will be in an oily area of the level, the car will run out of control for sure.