Blender and Integrations

Raycasts

Cast a body-local ray once or keep a configured query object.

Verified against the project sources on 19 September 2026.

Syntax#

Syntax
jolt_asset_get_raycast(asset, raycast_ref);
jolt_asset_raycast(asset, raycast_ref, owner_body, [options]);
jolt_asset_create_raycast(asset, raycast_ref, owner_body);

Factories return undefined on failure; inspect jolt_get_error() immediately. Authoring lookups return independent validated record copies. A reference is a canonical UUID or an exact, case-sensitive Key. Body owners must be live managed bodies in the current world.

World frame = current Body origin transform × authored local transform. The center of mass is not the authoring origin. Positions use metres and rotations use normalized XYZW quaternions. Refresh snapshots as the body moves.

Authoring defines position, rotation and length. Forward is local +Z. Length must be greater than 1e-6 and at most sqrt(FLT_MAX)/2 metres; extremely large world positions can still collapse endpoints. A cast samples the current world and is not a future trajectory or movement sweep.

API / fieldContract
options.layers / options.maskOne filter form only. mask is uint32; default 0 keeps normal query semantics.
options.ignoreOne live managed body, or undefined. The owner is not ignored by default.
options.lengthOptional validated override of authored length.
query.set_ignore(body | undefined)Boolean; rejected input preserves the previous filter.
query.cast()Normal nearest-hit result: inspect hit, error_code and error_message.

Example#

GML
// Create, once; Key "ground_front" must exist in the asset.
ground_ray = jolt_asset_create_raycast(asset, "ground_front", body_vehicle);
if (!is_undefined(ground_ray)) ground_ray.set_ignore(body_vehicle);
// Step, whenever a fresh result is needed:
if (!is_undefined(ground_ray)) {
    var hit = ground_ray.cast();
    if (hit.hit) show_debug_message(hit.distance);
    if (hit.error_code != 0) show_debug_message(hit.error_message);
}

The configured query stores a validated snapshot, follows current body transforms and rechecks owner/ignored-body validity on every cast. It allocates no native resource, has no automatic update and needs no destroy(). Drop references when finished. jolt_asset_raycast remains available for one-off calls with options.

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
AssetRaycast.castAssetRaycast.cast()Performs a current nearest query and returns the standard hit result including error state. Not a cached old hit.
AssetRaycast.get_rayAssetRaycast.get_ray()is_valid Boolean owner validity; get_ray current world origin/target/direction/length/filter without raycasting, undefined on error.
AssetRaycast.is_validAssetRaycast.is_valid()is_valid Boolean owner validity; get_ray current world origin/target/direction/length/filter without raycasting, undefined on error.
AssetRaycast.set_ignoreAssetRaycast.set_ignore(body)Live managed Body or undefined (ignore nothing); Boolean, rejected changes preserve previous filter.
jolt_asset_create_raycastjolt_asset_create_raycast(asset,raycast_ref,owner)Returns AssetRaycast/undefined with an independent record and borrowed owner. Allocates no native resource and performs no query; call cast for a new hit.
jolt_asset_get_raycastjolt_asset_get_raycast(asset,raycast_ref)Asset + exact key or canonical UUID. Revalidates the mutable asset and returns an independent data record, not a physics object; failure undefined and managed error.
jolt_asset_raycastjolt_asset_raycast(asset,raycast_ref,owner,options=undefined)Immediate nearest-hit result from owner world frame, local +Z. Options layers OR mask, ignore, length; owner is not implicitly ignored. Failure returns hit:false and error_code/message, not undefined.