Bodies

jolt_box_create_dynamic

Creates a Dynamic box in the default physics world.

Call jolt_start() successfully first. Dimensions are full lengths along the body's local axes; the position uses world-space Z-up coordinates.

Syntax#

Syntax
jolt_box_create_dynamic(x=0, y=0, z=0, width=1, depth=1, height=1, options=undefined);

All arguments may be omitted: this creates a unit box at the origin. Then use set_position and set_rotation_euler; geometry setters must match the shape type.

ArgumentTypeDescription
xRealFinite world-space X coordinate of the body centre; Z points up.
yRealFinite world-space Y coordinate of the body centre; Z points up.
zRealFinite world-space Z coordinate of the body centre; Z points up.
widthRealFull size along local X; finite and greater than zero.
depthRealFull size along local Y; finite and greater than zero.
heightRealFull size along local Z; finite and greater than zero.
optionsStruct | undefinedOPTIONAL. Defaults to undefined. Shared body settings; see Bodies Overview.

Returns#

JoltBody | undefined. Success returns a managed body. Invalid dimensions, position or options, and native creation failures return undefined. Read jolt_get_error() immediately.

Lifetime#

The caller owns the body. Call body.destroy() when it is no longer needed; jolt_stop() tears down the managed world. No rendering object is created.

Example#

Place the code in the object's Create and Cleanup events as marked. The world must exist when creating and destroying the body; update it once per frame with jolt_update().

GML
// Create event, after jolt_start() has succeeded.
body = jolt_box_create_dynamic(0, 0, 3, 1, 1, 1);
if (is_undefined(body)) {
    var error = jolt_get_error();
    show_debug_message(error.message);
}

// Cleanup event, while the world still exists.
if (!is_undefined(body)) body.destroy();

A unit box is created with its centre at height 3. The example handles creation failure and releases the body during cleanup.