‹›
Vehicles

Your First Vehicle

Builds, drives and renders the state of a basic four-wheel car with the minimum complete managed workflow.

The example uses local +Y as forward, lowers the chassis center of mass and lets driven wheel flags generate practical automatic differentials during build().

Create event#

GML
jolt_start({ gravity_z: -9.81 });

ground = jolt_box_create_static(0, 0, -0.5, 20, 200, 1);
chassis = jolt_box_create_dynamic(0, 0, 1.1, 1.8, 4.0, 0.5, {
    mass: 1200,
    center_of_mass_offset: { x:0, y:0, z:-0.25 }
});

car = jolt_vehicle(chassis, {
    collision: JOLT_VEHICLE_COLLISION_RAY,
    engine: { max_torque: 500 },
    transmission: { automatic: true }
});

car.add_wheel(-0.8,  1.4, -0.2, { radius:0.35, steering:true, driven:true });
car.add_wheel( 0.8,  1.4, -0.2, { radius:0.35, steering:true, driven:true });
car.add_wheel(-0.8, -1.4, -0.2, { radius:0.35, driven:true, handbrake:true });
car.add_wheel( 0.8, -1.4, -0.2, { radius:0.35, driven:true, handbrake:true });

car.add_anti_roll_bar(0, 1, 1000);
car.add_anti_roll_bar(2, 3, 1000);

if (!car.build()) {
    show_error(jolt_get_error_message(), true);
}

Step event#

GML
var throttle = keyboard_check(vk_up) - keyboard_check(vk_down);
var steering = keyboard_check(vk_right) - keyboard_check(vk_left);
var brake = keyboard_check(vk_space);
var handbrake = keyboard_check(ord("X"));

car.set_inputs(throttle, steering, brake, handbrake);
jolt_update();

Cleanup event#

GML
// jolt_stop() also destroys the managed vehicle and chassis safely.
jolt_stop();

What to verify#

  • car is a struct and car.build() returns true.
  • At least three or four wheels report has_contact after the chassis settles.
  • get_forward_speed() becomes positive under forward throttle and negative in automatic reverse.
  • Wheel transforms are read after jolt_update() for rendering.