Car and Camera Template

The car template includes all the functions and actions that are needed in order to get you started on creating a car racing game. In A7, the car templates are not included in the Project Manager: if you want to use one or several of them, please copy them manually from templates\code into your work folder (don't edit the original files in the templates\code folder!). In A8, the car templates are supported by the Project Manager, and can be added, removed, or customized.

Here's an example of a simple, yet fully functional main script that uses all of the car templates:

#include <acknex.h>
#include "car.h" // include player's car code
#include "camera.h" // include the car camera code
#include "car_ai.h" // include the enemy cars AI code
#include "car_props.h" // include the template car speedometer, rear mirror, racing timer, semaphore
#include "car_tracks.h" // include racetracks detection code for ice, grass, water and oil
function main() { video_mode = 8; // run at a 1024x768 pixels resolution level_load("racetrack01.wmb"); // use your own level name here }

You can include one or more of the .h scripts depending on your needs; all of them are either standalone, or include the extra files automatically.


This script file contains player's car code; as soon as you include it in your main script file, an action named "car_player" (A8) will appear in WED's action list and can be attached to a car body model (without wheels). Right click the t_car.h file in Wed's Resources / Script Files tab and then choose "Customize" if you want to edit the properties of the car. The properties are the same as in the car.c library.

You can also use skill1 (Player_speed) ... skill20 (Car_dampwheel) to set up the player car parameters from within WED. Set Flag1 for a hovercraft with invisible wheels. The default values work fine with most car models.



This script allows the player to use one of the 6 built-in cameras (orbit, chase, cockpit, fixed, first person, third person) for the game. You can set the default camera mode at game start, its chasing speed, angles and offsets by customizing the camera.h file in Wed.


Include this script in your main file and you will be able to use the following actions in Wed's action list:

1) t_race_finisher. This action can be attached to any entity that is placed at the end of the level. As soon as one of the cars (player's car or the enemy cars) comes close to it, the race will be over for that particular car. Feel free to add as many t_race_finisher entities as you need to your level if the racetrack is very wide.

2) t_ai_car. Attach this action to an enemy car model (up to 1,000 enemy cars can be used in a level) and it's going to set itself up automatically. You can also set up individual parameters for each car using its skills1 (Ai_speed) ... skill9 (Ai_scan_range) parameters if you want to.

Make sure to create a separate path for each car in Wed and place its origin close to the starting position of the car; the cars will detect and use the closest paths to them at startup.

Feel free to customize the t_car_ai.h script using Wed's "resources -> script files" tab. The "end of race" trigger value sets the distance (in quants) that will end the race if the cars come close to the entity that has the "t_race_finisher" action attached to it.


This script contains various props:

1) Speedometer;

2) High precission racing timer;

3) Semaphore;

4) Water shader (useful if your levels contain water).

The speedometer, the timer and the semaphore are activated automatically by simply including the t_car_props.h file in your project; nevertheless, you can customize their behavior or disable them completely from within Wed.

The water uses Gamestudio's built-in shader that comes with the mtlFX.c library; attach the fx_water_enviro action to your water model or terrain and it will activate if your engine version and your video card supports it (a V.S. / P.S. 2.0 video card or better is required). If you have a weak video card or a low engine version, the water will use a simple texture shifting effect.


This script modifies player's car behavior (speed, friction, rotation, etc) if it moves over the icy, grassy or oily areas of the level: the car will slow down if at least one of its wheels touches the grass and will be much hard to control if its wheels touch the icy areas. The car will run out of control if its wheels touch an oily area in the level. In addition to that, the script will generate water splash particle effects and water sound effects if player's wheels touch a water surface in the level.

Start by assigning the action named "tcar_terrain" to the terrain or model entity that is used for the level. The grass, ice, etc behavior isn't triggered by the color of the level texture; a special bitmap needs to be prepared if you want to use this feature. Export the skin of the terrain or model that is used for the level and name it "colormap.tga". Paint the areas that are supposed to be icy with RGB = 255 255 255 in your favorite painting application, use RGB = 0 255 0 for the grass (the areas that slow down the car), RGB = 0 0 0 for the oil and RGB = 0 0 255 for the water - here's a colormap.tga example:

In this example, player's car would drive normally in the red area and would be affected by grass, water, ice and oil in the green, blue, white and black areas. The active colormap.tga colors, as well as the water particles properties can be customized from within Wed, as shown below.