Creating a Vehicle
Creates a managed vehicle draft over a valid Dynamic chassis and returns JoltVehicle or undefined.
Creation selects the collision tester and controller-wide orientation limits. Wheels and drivetrain are configured on the returned draft before build().
Syntax#
jolt_vehicle(chassis, options=undefined)Arguments#
| Argument | Type | Description |
|---|---|---|
| chassis | JoltBody | Live Dynamic, non-sensor body in the managed world. |
| options | Struct or undefined | Optional collision, orientation, engine and transmission configuration. |
Vehicle options#
| Field | Default | Rules / purpose |
|---|---|---|
| collision | JOLT_VEHICLE_COLLISION_RAY | Ray, Sphere or Cylinder wheel-ground tester constant. |
| collision_radius | 0.05 | Finite positive cast radius used by the Sphere tester. |
| maximum_slope_angle | 80 | Finite degrees greater than 0 and less than 90. |
| maximum_pitch_roll_angle | 180 | Finite degrees greater than 0 and at most 180. |
| engine | undefined | Optional engine settings documented on the Engine page. |
| transmission | undefined | Optional transmission mode, timings and gear ratios. |
Return value#
Returns a JoltVehicle draft on success. Returns undefined and sets the high-level error when the chassis or any supplied setting is invalid.
Build contract#
- Add between 2 and 32 wheels before calling build().
- Provide at least one driven wheel or add an explicit differential.
- Add differentials and anti-roll bars before build().
- build() is idempotent through the managed wrapper: a second call after success returns true.
- Runtime input and getters require a successfully built vehicle.
var car = jolt_vehicle(chassis, {
collision: JOLT_VEHICLE_COLLISION_SPHERE,
collision_radius: 0.08,
maximum_slope_angle: 55,
maximum_pitch_roll_angle: 75
});
if (is_undefined(car)) {
var error = jolt_get_error();
show_debug_message(error.context + ": " + error.message);
}Configuration object and setters#
var settings = jolt_vehicle_settings();
settings.set_collision(JOLT_VEHICLE_COLLISION_SPHERE);
settings.set_collision_radius(0.08);
var car = jolt_vehicle(chassis, settings);Configuration factories return a GML settings object and create no physics. Their setters return self, the settings object, and do not confirm that a value is valid. Fields are consumed and validated by jolt_vehicle, add_wheel or add_differential. An omitted field preserves the corresponding options default described above. Editing settings after consumption does not change an existing vehicle, wheel or differential. Settings need no destroy.
Vehicle creation returns undefined on failure. add_differential returns Boolean; add_wheel returns a numeric zero-based index or Boolean false on failure. Index 0 is success: do not use only if (!wheel_index). Complete wheel/differential configuration before build().
Verified operation contracts#
These contracts distinguish units, return values, errors and lifetime according to the current implementation. Check results: false, 0 and undefined can mean different things for different methods.
| Symbol / owner | Signature | Operation contract |
|---|---|---|
| jolt_vehicle | jolt_vehicle(chassis, options = undefined) | Live non-sensor Dynamic chassis + optional options/settings. Returns JoltVehicle or undefined; does not own the chassis. Add wheels and call build. Engine/transmission failure destroys the draft Vehicle, not the chassis. |
| jolt_vehicle_settings | jolt_vehicle_settings() | Creates an empty settings object. No world required, no physics created; setters return self. Omitted properties retain defaults at jolt_vehicle. |
| JoltVehicle.build | JoltVehicle.build() | Boolean; finalizes 2–32 wheels on a Dynamic chassis. Repeated calls after success return true; wheel construction cannot be changed after build. |
| JoltVehicleSettings.set_collision | JoltVehicleSettings.set_collision(value) | Pre-creation configuration; returns self, validation deferred to jolt_vehicle/add_wheel/add_differential. JOLT_VEHICLE_COLLISION_RAY/SPHERE/CYLINDER mode; default RAY. |
| JoltVehicleSettings.set_collision_radius | JoltVehicleSettings.set_collision_radius(value) | Pre-creation configuration; returns self, validation deferred to jolt_vehicle/add_wheel/add_differential. Test radius in m, default 0.05; positive finite. |
| JoltVehicleSettings.set_engine | JoltVehicleSettings.set_engine(value) | Pre-creation configuration; returns self, validation deferred to jolt_vehicle/add_wheel/add_differential. Corresponding settings object or options struct; does not change a running engine/transmission. |
| JoltVehicleSettings.set_maximum_pitch_roll_angle | JoltVehicleSettings.set_maximum_pitch_roll_angle(value) | Pre-creation configuration; returns self, validation deferred to jolt_vehicle/add_wheel/add_differential. Angles in degrees; defaults slope 80°, pitch/roll 180°. |
| JoltVehicleSettings.set_maximum_slope_angle | JoltVehicleSettings.set_maximum_slope_angle(value) | Pre-creation configuration; returns self, validation deferred to jolt_vehicle/add_wheel/add_differential. Angles in degrees; defaults slope 80°, pitch/roll 180°. |
| JoltVehicleSettings.set_transmission | JoltVehicleSettings.set_transmission(value) | Pre-creation configuration; returns self, validation deferred to jolt_vehicle/add_wheel/add_differential. Corresponding settings object or options struct; does not change a running engine/transmission. |