Reference / Physics & grids handle 5 methods, 1 field UI apps only
PhysicsWorld An isolated physics world created by datumhue.physics.world() . Bodies join it via add_body{world = ...}; queries and gravity are scoped to it.
Obtained from datumhue.physics.worldAccepted by SceneNode:add_body , DrawCanvas:body , DrawPrimitive:add_bodyThe examples on this page start from:
Fields 1
Field Type Access Description gravityVec3 read/write This world's gravity vector (Y-up; default {0, -9.81, 0}). 2D bodies feel its X/Y components. Assign a vec2/vec3. Example
world.gravity = vec3 (0 , 200 , 0 )
print (world.gravity)
print (datumhue .physics.gravity )
Methods 5
PhysicsWorld: raycastmethod Cast a ray and return the nearest body hit, or nil. An options value that is not a table is ignored.
Example
datumhue .time.sleep (0.1 )
local down = datumhue .math.ray (vec3 (0 , 100 , 0 ), vec3 (0 , -1 , 0 ))
print (world:raycast (down, { max_distance = 500 }).distance)
print (datumhue .physics.raycast (down)) options physics.RaycastOptions options 4 keys
Key Type Default Description max_distance number 1000000 Maximum ray length in world units, 0 or more; math.huge casts without a limit. layers integer[] every layer Only hit bodies in these layer bit indices 0..=31. exclude DrawPrimitive | SceneNode | Voxel no body is ignored A body to ignore. solid boolean true Count a ray starting inside a collider as a hit at distance 0.
returns physics.RayHit record 4 keys
Key Type Description body DrawPrimitive | SceneNode | Voxel The body that was hit. point Vec3 World-space contact point. normal Vec3 World-space surface normal at the hit. distance number Distance from the origin to the hit.
PhysicsWorld: raycast_allmethod Cast a ray and return every body along it, nearest first. An options value that is not a table is ignored.
options physics.RaycastAllOptions options 5 keys, 4 inherited
Key Type Default Description max_hits integer 64 Maximum hits to return, 0 or more. From physics.RaycastOptions max_distance number 1000000 Maximum ray length in world units, 0 or more; math.huge casts without a limit. layers integer[] every layer Only hit bodies in these layer bit indices 0..=31. exclude DrawPrimitive | SceneNode | Voxel no body is ignored A body to ignore. solid boolean true Count a ray starting inside a collider as a hit at distance 0.
returns physics.RayHit record 4 keys
Key Type Description body DrawPrimitive | SceneNode | Voxel The body that was hit. point Vec3 World-space contact point. normal Vec3 World-space surface normal at the hit. distance number Distance from the origin to the hit.
PhysicsWorld: point_querymethod Return every body whose collider overlaps the given world-space point. An options value that is not a table is ignored.
PhysicsWorld: shapecastmethod Sweep a 3D collider shape along the ray and return the nearest body hit, or nil.
options physics.ShapecastOptions options 9 keys
Key Type Default Description shape physics.Shape "cube" 3D collider shape to cast. width number 1 Box width. height number 1 Box height / capsule length. depth number 1 Box depth. radius number 0.5 Sphere / capsule / cylinder / cone radius. rotation Quat datumhue.math.quat.identity() Shape orientation. max_distance number 1000000 Maximum cast length in world units, 0 or more; math.huge casts without a limit. layers integer[] every layer Only hit bodies in these layer bit indices 0..=31. exclude DrawPrimitive | SceneNode | Voxel no body is ignored A body to ignore.
returns physics.RayHit record 4 keys
Key Type Description body DrawPrimitive | SceneNode | Voxel The body that was hit. point Vec3 World-space contact point. normal Vec3 World-space surface normal at the hit. distance number Distance from the origin to the hit.
PhysicsWorld: removemethod PhysicsWorld:remove ()
Drop this world and every body and joint simulating in it.