Namespace: b2d.world
Language: Lua
Type: Defold Lua
File: script_box2d_world_v2.cpp
Source: engine/gamesys/src/gamesys/scripts/box2d/v2/script_box2d_world_v2.cpp
Query and cast functions for the Defold-owned Box2D v2 world.
Type: FUNCTION The capsule table has center1, center2, and radius fields. The return value is the fraction of translation that can be traveled before collision, or 1 if there is no hit.
Parameters
world (b2World) - worldcapsule (table) - capsule table with center1, center2, and radiustranslation (vector3) - capsule displacementfilter (table) (optional) - optional query filter with category_bits and mask_bitsReturns
fraction (number) - travel fraction before collisionType: FUNCTION Cast a ray.
Parameters
world (b2World) - world from b2d.get_world or b2d.body.get_worldorigin (vector3) - world ray origintranslation (vector3) - world ray translationfilter (table) - optional query filter with category_bits, mask_bits, and optional group_indexmax_results (number) - optional maximum result countReturns
hits (table) - array of hit tables with fixture, shape, point, normal, and fractionstats (table) - table with node_visits and leaf_visitsType: FUNCTION The translation is the ray displacement from origin. Result order is not guaranteed by Box2D.
Parameters
world (b2World) - worldorigin (vector3) - ray start positiontranslation (vector3) - ray displacementfilter (table) (optional) - optional query filter with category_bits and mask_bitsmax_results (number) (optional) - optional maximum result count. Omit or pass 0 for unlimited results.Returns
hits (table) - array of cast hit tablesstats (table) - tree stats tableType: FUNCTION Cast a ray and return the closest hit.
Parameters
world (b2World) - world from b2d.get_world or b2d.body.get_worldorigin (vector3) - world ray origintranslation (vector3) - world ray translationfilter (table) - optional query filter with category_bits, mask_bits, and optional group_indexReturns
hit (table) - hit table with fixture, shape, point, normal, fraction, node_visits, and leaf_visits, or nilType: FUNCTION The translation is the ray displacement from origin.
Parameters
world (b2World) - worldorigin (vector3) - ray start positiontranslation (vector3) - ray displacementfilter (table) (optional) - optional query filter with category_bits and mask_bitsReturns
hit (table |
nil) - closest cast hit table with node_visits and leaf_visits, or nil on miss |
Type: FUNCTION Uses Box2D v2 time-of-impact for fixture child shapes that support distance proxies. Grid fixture children are skipped.
Parameters
world (b2World) - world from b2d.get_world or b2d.body.get_worldshape (table) - shape table using the same format as the shape field in b2d.body.create_fixturetranslation (vector3) - world shape translationfilter (table) - optional query filter with category_bits, mask_bits, and optional group_indexmax_results (number) - optional maximum result countReturns
hits (table) - array of hit tables with fixture, shape, point, normal, and fractionstats (table) - table with node_visits and leaf_visitsType: FUNCTION The shape table uses the same circle, capsule, segment, polygon, and box formats as b2d.body.create_shape. The translation is the shape displacement.
Parameters
world (b2World) - worldshape (table) - shape tabletranslation (vector3) - shape displacementfilter (table) (optional) - optional query filter with category_bits and mask_bitsmax_results (number) (optional) - optional maximum result count. Omit or pass 0 for unlimited results.Returns
hits (table) - array of cast hit tablesstats (table) - tree stats tableType: FUNCTION The capsule table has center1, center2, and radius fields. Plane result tables include shape, normal, offset, and hit.
Parameters
world (b2World) - worldcapsule (table) - capsule table with center1, center2, and radiusfilter (table) (optional) - optional query filter with category_bits and mask_bitsmax_results (number) (optional) - optional maximum result count. Omit or pass 0 for unlimited results.Returns
planes (table) - array of plane result tablesType: FUNCTION Enable or disable continuous collision.
Parameters
world (b2World) - worldenable (boolean) - true to enable continuous collisionType: FUNCTION Enable or disable world sleeping.
Parameters
world (b2World) - worldenable (boolean) - true to allow sleepingType: FUNCTION Enable or disable speculative collision.
Parameters
world (b2World) - worldenable (boolean) - true to enable speculative collisionType: FUNCTION Enable or disable warm starting.
Parameters
world (b2World) - worldenable (boolean) - true to enable warm startingType: FUNCTION The definition table requires position, radius, falloff, and impulse_per_length. It may also include mask_bits.
Parameters
world (b2World) - worlddefinition (table) - explosion definitionType: FUNCTION Get the number of awake bodies.
Parameters
world (b2World) - worldReturns
count (number) - awake body countType: FUNCTION The returned table contains body_count, shape_count, contact_count, joint_count, island_count, stack_used, static_tree_height, tree_height, byte_count, task_count, and color_counts.
Parameters
world (b2World) - worldReturns
counters (table) - world countersType: FUNCTION Get world gravity.
Parameters
world (b2World) - worldReturns
gravity (vector3) - gravity vectorType: FUNCTION Get the hit event threshold.
Parameters
world (b2World) - worldReturns
threshold (number) - hit event threshold in project units per secondType: FUNCTION Get the maximum linear speed.
Parameters
world (b2World) - worldReturns
speed (number) - maximum linear speed in project units per secondType: FUNCTION The returned table contains Box2D timing fields including step, pairs, collide, solve, merge_islands, prepare_stages, solve_constraints, prepare_constraints, integrate_velocities, warm_start, solve_impulses, integrate_positions, relax_impulses, apply_restitution, store_impulses, split_islands, transforms, hit_events, refit, bullets, sleep_islands, and sensors.
Parameters
world (b2World) - worldReturns
profile (table) - world profiling dataType: FUNCTION Get the restitution threshold.
Parameters
world (b2World) - worldReturns
threshold (number) - restitution threshold in project units per secondType: FUNCTION Get whether continuous collision is enabled.
Parameters
world (b2World) - worldReturns
enabled (boolean) - true if continuous collision is enabledType: FUNCTION The world is locked during callbacks and some simulation phases. Functions marked as locked during callbacks cannot be called while this returns true.
Parameters
world (b2World) - worldReturns
locked (boolean) - true if the world is lockedType: FUNCTION Get whether world sleeping is enabled.
Parameters
world (b2World) - worldReturns
enabled (boolean) - true if sleeping is enabledType: FUNCTION Check whether a world handle is valid.
Parameters
world (b2World) - worldReturns
valid (boolean) - true if the world handle is validType: FUNCTION Get whether warm starting is enabled.
Parameters
world (b2World) - worldReturns
enabled (boolean) - true if warm starting is enabledType: FUNCTION Overlap an AABB.
Parameters
world (b2World) - world from b2d.get_world or b2d.body.get_worldaabb (table) - table with lower and upper vector3 fieldsfilter (table) - optional query filter with category_bits, mask_bits, and optional group_indexmax_results (number) - optional maximum result countReturns
fixtures (table) - array of fixture info tablesstats (table) - table with node_visits and leaf_visitsType: FUNCTION The AABB table has lower and upper vector3 fields.
Parameters
world (b2World) - worldaabb (table) - AABB table with lower and upperfilter (table) (optional) - optional query filter with category_bits and mask_bitsmax_results (number) (optional) - optional maximum result count. Omit or pass 0 for unlimited results.Returns
hits (table) - array of shape info tablesstats (table) - tree stats tableType: FUNCTION Overlap a shape.
Parameters
world (b2World) - world from b2d.get_world or b2d.body.get_worldshape (table) - shape table using the same format as the shape field in b2d.body.create_fixturefilter (table) - optional query filter with category_bits, mask_bits, and optional group_indexmax_results (number) - optional maximum result countReturns
fixtures (table) - array of fixture info tablesstats (table) - table with node_visits and leaf_visitsType: FUNCTION The shape table uses the same circle, capsule, segment, polygon, and box formats as b2d.body.create_shape.
Parameters
world (b2World) - worldshape (table) - shape tablefilter (table) (optional) - optional query filter with category_bits and mask_bitsmax_results (number) (optional) - optional maximum result count. Omit or pass 0 for unlimited results.Returns
hits (table) - array of shape info tablesstats (table) - tree stats tableType: FUNCTION Rebuild the static broad-phase tree.
Parameters
world (b2World) - worldType: FUNCTION Set contact solver tuning.
Parameters
world (b2World) - worldhertz (number) - contact stiffness frequency in hertzdamping_ratio (number) - contact damping ratiopushout (number) - pushout velocity in project units per secondType: FUNCTION Set world gravity.
Parameters
world (b2World) - worldgravity (vector3) - gravity vectorType: FUNCTION Set the hit event threshold.
Parameters
world (b2World) - worldthreshold (number) - hit event threshold in project units per secondType: FUNCTION Set joint solver tuning.
Parameters
world (b2World) - worldhertz (number) - joint stiffness frequency in hertzdamping_ratio (number) - joint damping ratioType: FUNCTION Set the maximum linear speed.
Parameters
world (b2World) - worldspeed (number) - maximum linear speed in project units per secondType: FUNCTION Collisions below this relative speed use inelastic collision response.
Parameters
world (b2World) - worldthreshold (number) - restitution threshold in project units per second