race track | gml
| Type | Desc | |
|---|---|---|
| viewport | property | allows us to set up our 'camera' to focus or view a segmented portion of the room in the game window. great for large maps or areas etc. |
| image_angle | variable | current angle at which the image will be drawn. |
| Sprite | Images |
|---|---|
| sprCar | ![]() |
| sprTrack3072x2304 | ![]() |
Place origin between the front wheels for FWD steering / handling (feel free to try back wheels to simulate RWD):
Finally, set race track collision mask to precise (slow). This is not an ideal long-term solution, but will do while we are learning GML:
| Object | Sprite | Properties |
|---|---|---|
| objCar | sprCar | Visible |
| objTrack | sprTrack3072x2304 | Visible |
objCar Step
//on-road max speed:
var max_speed = 20;
//check if on or off-road:
if not(place_meeting(x, y, objTrack)){
//car is off-road, so cap max speed:
max_speed = 5;
//if we go on ro off-road, speed will be too high...
if (speed > max_speed){
//... so decay speed gradually each step:
speed = speed * 0.95;
}
}
//steering:
if (keyboard_check(vk_left)){
image_angle = image_angle + 3;
direction = direction + 3;
}
if (keyboard_check(vk_right)){
image_angle = image_angle - 3;
direction = direction - 3;
}
//accelerate:
if (keyboard_check(vk_up)){
if (speed < max_speed){
speed = speed + 0.5;
}
}
Challenges
- Add an emergency / hand brake
- Add a boost / NOS button


