Shape Queries

Shape Casts

A cast translates a shape between two world-space centres with a fixed orientation. It is not a rotational sweep and does not resolve movement or slide along obstacles for you. Choose the closest form for a blocking obstacle and _all for all bodies along a path.

GML
jolt_cast_box(sx, sy, sz, ex, ey, ez, width, depth, height, options=undefined)
jolt_cast_sphere(sx, sy, sz, ex, ey, ez, radius, options=undefined)
jolt_cast_capsule(sx, sy, sz, ex, ey, ez, height, radius, options=undefined)
jolt_cast_shape(shape, sx, sy, sz, ex, ey, ez, options=undefined)
// The same argument lists apply to jolt_cast_*_all.

A successful miss has hit: false, fraction: 1 and distance: 0; distance is not the full query length on a miss. All-hit casts keep one closest hit per body, sorted by increasing fraction. A starting penetration has fraction: 0 and initial_overlap: true; it needs overlap recovery, not ordinary forward movement.

GML
var r = jolt_cast_sphere(0, 0, 2, 10, 0, 2, 0.25);
if (r.error_code != 0) show_debug_message(r.error_message);
else if (r.hit) show_debug_message(r.shape_position);

var hits = jolt_cast_sphere_all(0, 0, 2, 10, 0, 2, 0.25);
if (jolt_has_error()) show_debug_message(jolt_get_error_message());
else show_debug_message(array_length(hits));

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
jolt_cast_boxjolt_cast_box(sx,sy,sz,ex,ey,ez,width,depth,height,options=undefined)World start/end points m, fixed orientation and dimensions as overlap; generic convex-compatible resource only. Does not rotate shape during sweep. Nearest hit struct or hit:false, error_code/message. Fields position, query_position, shape_position, normal, penetration_depth, fraction, distance, subshape IDs, initial_overlap, body/entity.
jolt_cast_box_alljolt_cast_box_all(sx,sy,sz,ex,ey,ez,width,depth,height,options=undefined)Same parameters as nearest cast, returns hit array instead of one. [] means no hit or failure; distinguish through jolt_get_error. No temporary body or movement of existing bodies.
jolt_cast_capsulejolt_cast_capsule(sx,sy,sz,ex,ey,ez,height,radius,options=undefined)World start/end points m, fixed orientation and dimensions as overlap; generic convex-compatible resource only. Does not rotate shape during sweep. Nearest hit struct or hit:false, error_code/message. Fields position, query_position, shape_position, normal, penetration_depth, fraction, distance, subshape IDs, initial_overlap, body/entity.
jolt_cast_capsule_alljolt_cast_capsule_all(sx,sy,sz,ex,ey,ez,height,radius,options=undefined)Same parameters as nearest cast, returns hit array instead of one. [] means no hit or failure; distinguish through jolt_get_error. No temporary body or movement of existing bodies.
jolt_cast_shapejolt_cast_shape(shape,sx,sy,sz,ex,ey,ez,options=undefined)World start/end points m, fixed orientation and dimensions as overlap; generic convex-compatible resource only. Does not rotate shape during sweep. Nearest hit struct or hit:false, error_code/message. Fields position, query_position, shape_position, normal, penetration_depth, fraction, distance, subshape IDs, initial_overlap, body/entity.
jolt_cast_shape_alljolt_cast_shape_all(shape,sx,sy,sz,ex,ey,ez,options=undefined)Same parameters as nearest cast, returns hit array instead of one. [] means no hit or failure; distinguish through jolt_get_error. No temporary body or movement of existing bodies.
jolt_cast_spherejolt_cast_sphere(sx,sy,sz,ex,ey,ez,radius,options=undefined)World start/end points m, fixed orientation and dimensions as overlap; generic convex-compatible resource only. Does not rotate shape during sweep. Nearest hit struct or hit:false, error_code/message. Fields position, query_position, shape_position, normal, penetration_depth, fraction, distance, subshape IDs, initial_overlap, body/entity.
jolt_cast_sphere_alljolt_cast_sphere_all(sx,sy,sz,ex,ey,ez,radius,options=undefined)Same parameters as nearest cast, returns hit array instead of one. [] means no hit or failure; distinguish through jolt_get_error. No temporary body or movement of existing bodies.