Body Properties

Gravity

Configures world gravity and each body's gravity multiplier.

The managed world defaults to {x:0,y:0,z:-9.81}. A body's gravity_factor multiplies that vector without changing the global world setting.

World gravity at startup#

GML
jolt_start({
    gravity_x: 0,
    gravity_y: 0,
    gravity_z: -9.81
});

gravity_x, gravity_y, and gravity_z are supplied when the default world is created. The high-level runtime does not expose a world-gravity setter after startup; stop and recreate the world to choose another global vector.

Per-body API#

GML
body.set_gravity_factor(value)
body.get_gravity_factor()

Factor behaviour#

FactorEffect
1Full world gravity; default
0No world-gravity acceleration
0..1Reduced gravity
> 1Amplified gravity
< 0Reversed gravity direction

The factor accepts any finite Real. It requires body motion properties and is meaningful for simulated non-Static motion. Gravity acceleration remains independent of mass, while an equivalent compensating force is proportional to body mass.

Example#

GML
var moon_crate = jolt_box_create_dynamic(0, 0, 5, 1, 1, 1, {
    mass: 4,
    gravity_factor: 0.165
});

moon_crate.set_gravity_factor(0);

Low-Level / Advanced API#

Setters return true on success and false on invalid input, an invalid or stale body, or an unsupported motion type. Getters return the requested value or undefined when the operation fails. Inspect jolt_get_error() for the high-level error.

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 / ownerSignatureOperation contract
JoltBody.get_gravity_factorJoltBody.get_gravity_factor()Finite gravity multiplier; setter Boolean, getter number or undefined. 0 disables gravity acceleration, not mass.
JoltBody.set_gravity_factorJoltBody.set_gravity_factor(value)Finite gravity multiplier; setter Boolean, getter number or undefined. 0 disables gravity acceleration, not mass.