Skip to content

Search

Documentation

physics2d

The 2D rigid-body world: bodies and colliders on nodes, their velocities, raycasts and overlap queries. physics holds what spans both worlds.

On this page

The 2D rigid-body world: bodies and colliders on nodes, their velocities, raycasts and overlap queries. physics holds what spans both worlds.

118 functions, 106 constants. Scripts reach it as physics2d::.

Acts on body2d, character2d, collider2d, follow2d, joint2d, softbody2d: those functions are also methods on the component's handle, without the node argument.

Functions

Argument kinds are the script values a call passes: node is a node handle, any a table or value of any kind, fn a callback.

function acts on what it does
aabb(Node) -> physics2d::Aabb collider2d The world-space box the collider currently occupies, from its lowest corner to its highest.
add_constant_force(Node, Vec2) body2d Push the body every step until the constant force is set back to zero; unlike an impulse this is spread over time.
add_constant_force_at_point(Node, Vec2, Vec2) body2d Push at a world point every step, which also turns the body.
add_constant_torque(Node, float) body2d Turn the body every step until the constant torque is set back to zero.
add_particle_force(Node, int, Vec2) softbody2d Push one particle with force each step until reset_forces.
add_softbody_force(Node, Vec2) softbody2d Push every free particle with force each step until reset_forces.
angular_velocity(Node) -> float body2d How fast the body is spinning, in radians per second.
apply_force(Node, Vec2) body2d Push the body for the next step only; add_constant_force keeps pushing.
apply_force_at_point(Node, Vec2, Vec2) body2d Push at a world point for the next step only, which also turns the body.
apply_impulse(Node, Vec2) body2d Add an instant change in momentum, as if the body were struck.
apply_impulse_at_point(Node, Vec2, Vec2) body2d Strike the body at a world point, which spins it as well as moves it.
apply_particle_impulse(Node, int, Vec2) softbody2d Strike one particle.
apply_softbody_impulse(Node, Vec2) softbody2d Change every free particle's velocity by impulse at once, as a kick to the whole body.
apply_softbody_impulse_at_point(Node, Vec2, Vec2, float) softbody2d Strike the particles within radius of point, less the further they are; a radius of 0 strikes them all.
apply_softbody_radial_impulse(Node, Vec2, float, float) softbody2d Push the particles within radius away from center, as a blast does.
apply_torque(Node, float) body2d Turn the body for the next step only; add_constant_torque keeps turning it.
apply_torque_impulse(Node, float) body2d Add an instant change in angular momentum, as if the body were spun.
attach_particle(Node, int, Node) softbody2d Tie one particle to a node's rigid body where it is now: the body and the particle pull on each other.
broad_phase_aabb(Node) -> physics2d::Aabb collider2d The box the broad phase files the collider under, which also reaches ahead by its body's speculative_distance.
closest_point(physics2d::PointQuery) -> physics2d::Closest? — The closest point on any collider to a world point.
closest_points(Node, Node) -> physics2d::ClosestPoints? — The nearest point on each of two nodes' colliders; nothing when they overlap.
collider_mass_properties(Node) -> physics2d::MassProperties collider2d What this collider adds to its body, in its own space.
collider_mesh(Node) -> physics2d::ColliderMesh collider2d A voxel collider's outline as points and the segments between them, for drawing it or for spawning the pieces it broke into.
collider_volume(Node) -> float collider2d How much area the shape encloses.
collision_aabb(Node) -> physics2d::Aabb collider2d The box the narrow phase tests the collider in: its shape's box grown by its collision_margin and the world's prediction distance.
combine_voxels(Node, Node) collider2d Tell two voxel colliders on one lattice about each other's cells, so a body sliding from one onto the other does not catch on the seam. Both must share a cell size and a rotation.
constant_force(Node) -> Vec2 body2d The force every step integrates until it is set back to zero.
constant_torque(Node) -> float body2d The torque every step integrates until it is set back to zero.
contacts(Node) -> [physics2d::Contact] collider2d Every contact point on this node's collider this step. Empty for a sensor, which has no contacts by definition.
crop_voxels(Node, int, int, int, int) collider2d Empty every cell outside the cells from (min_x, min_y) to (max_x, max_y), both included. A range holding no filled cell leaves the grid as it was.
cut_softbody(Node, [Vec2]) -> [physics2d::SoftTear] softbody2d Cut the body along a blade at once, as crossing reads it; answers a record for each piece it changed, the one on_torn hears.
detach_particle(Node, int) -> bool softbody2d Untie one particle from every body it was attached to; answers whether it was attached.
effective_angular_inertia(Node) -> float body2d The inertia the solver turns: zero with rotation locked, and on any body that is not dynamic.
effective_dominance(Node) -> float body2d The dominance rapier will use for this body: its own group, or the rank every non-dynamic body outranks with.
effective_mass(Node) -> Vec2 body2d The mass the solver pushes against along each world axis: zero along a locked axis, and on any body that is not dynamic.
gravity() -> Vec2 — The 2D world's gravity.
handles(Node) -> physics2d::Handles collider2d The rapier handles behind this node, its body and its colliders. For matching a log line against rapier's own output.
has_pending_tears(Node) -> bool softbody2d Whether some edge or cell is marked to tear at the end of the next step.
heightfield_hole(Node, int) -> bool collider2d Whether a heightfield segment has no ground.
intersects(Node, Node) -> bool — Whether two nodes' colliders overlap right now, sensor or not.
is_ccd_active(Node) -> bool body2d Whether the body moved fast enough last step for rapier to sweep it, with or without continuous_collision.
is_moving(Node) -> bool body2d Whether the body is awake and actually going somewhere.
is_sleeping(Node) -> bool body2d Whether the body is asleep and being skipped.
is_softbody_sleeping(Node) -> bool softbody2d Whether the body has come to rest and stopped being simulated.
joint_force(Node) -> physics2d::JointForce joint2d The force and the torque the joint held through the last step. An articulation has none to read, and says so.
joint_state(Node) -> physics2d::JointState joint2d What the joint is doing.
kinetic_energy(Node) -> float body2d The body's kinetic energy, for a rest test the solver agrees with.
linear_velocity(Node) -> Vec2 body2d How fast the body is travelling, in units per second.
local_center_of_mass(Node) -> Vec2 body2d Where the body's whole mass sits, in the body's own space.
max_contact_impulse(Node) -> float body2d The hardest contact this body took in the last step, every collider on it included; zero when nothing touched it.
move_character_by(Node, Vec2) -> physics2d::CharacterMove character2d Move the character by an offset, sliding along walls, climbing steps and staying on the ground. Every solid collider of the character is swept. Call it from fixed_update.
next_position(Node) -> physics2d::Pose body2d The pose a kinematic body has been told to move to.
overlap_aabb(physics2d::BoxQuery) -> [Node] — Every collider whose bounds meet an axis-aligned box.
overlap_point(physics2d::PointQuery) -> [Node] — Every collider containing a world point: what a mouse click asks.
overlap_shape(physics2d::ShapeQuery) -> [Node] — Every collider a shape overlaps where it stands.
overlaps(Node) -> [Node] collider2d The nodes this one currently intersects; rapier reports a pair only when one of the two colliders is a sensor.
pin_particle(Node, int) softbody2d Hold one particle where it is, which is how a cloth hangs from a hook.
pose_in_body(Node) -> physics2d::Pose? collider2d Where the collider sits in its body's frame; nothing for a collider with no body.
potential_energy(Node) -> float body2d The body's gravitational potential energy over one step.
predict_position(Node, float) -> physics2d::Pose body2d Where the body will be after dt seconds at its current velocity.
predict_position_with_forces(Node, float) -> physics2d::Pose body2d The same, with the forces already applied taken into account: where a thrust or a spring will have put it.
raycast(physics2d::RayQuery) -> physics2d::Hit? — The first collider a ray meets, or nothing.
raycast_all(physics2d::RayQuery) -> [physics2d::Hit] — Every collider a ray meets, nearest first.
reset_follow(Node) follow2d Forget what a pid follow summed, so it pulls from now as if it had just started.
reset_plasticity(Node) softbody2d Undo every permanent set the body took: rest lengths, rest angles and rest shapes go back to how it was built, and it springs back from where it is.
reset_softbody_forces(Node) softbody2d Take back every force add_force and add_particle_force gave the body.
set_angular_velocity(Node, float) body2d Set how fast the body spins, in radians per second.
set_cell_tear_resistance(Node, int, float) softbody2d The same for one cell's tear strain.
set_constant_force(Node, Vec2) body2d Replace the constant force with this one; zero stops the push.
set_constant_torque(Node, float) body2d Replace the constant torque with this one; zero stops the turn.
set_edge_tear_resistance(Node, int, float) softbody2d How many times the material's threshold one edge takes to tear; 1 is the material's.
set_gravity(Vec2) — Set the 2D world's gravity, in units per second squared.
set_heightfield_hole(Node, int, bool) collider2d Remove or restore one segment of a heightfield's ground, numbered from the first height.
set_linear_velocity(Node, Vec2) body2d Set how fast the body travels, in units per second.
set_particle_damaged(Node, int, bool) softbody2d Mark one particle as damaged or mend it: a damaged particle tears as an outside one does, which seeds where a crack starts.
set_particle_position(Node, int, Vec2) softbody2d Put one particle at at with no change of velocity.
set_particle_target(Node, int, Vec2) softbody2d Move a held particle to at over the next step, with the velocity that takes, which is how a cloth is dragged.
set_particle_velocity(Node, int, Vec2) softbody2d Set one particle's velocity; a held one keeps moving at it.
set_voxel(Node, int, int, bool) collider2d Fill or empty one cell of a voxel collider: digging a hole, or building a wall, while the game runs.
set_voxel_size(Node, Vec2) collider2d Resize every cell of a voxel collider, keeping which cells are filled.
shapecast(physics2d::ShapeQuery) -> physics2d::Hit? — Sweep a shape along a direction until it hits something: a thick raycast.
sleep(Node) body2d Put the body to sleep now.
softbody_area(Node) -> float softbody2d How much area the body and every piece torn off it enclose right now, against rest_area for how far it is squeezed.
softbody_attachments(Node) -> [physics2d::SoftAttachment] softbody2d Every particle tied to a rigid body.
softbody_boundary(Node) -> [[int]] softbody2d The body's surface as particle indices: segments in 2D, triangles in 3D.
softbody_cell(Node, int) -> physics2d::SoftCell softbody2d Everything one cell holds.
softbody_cells(Node) -> [[int]] softbody2d Every cell as its particle indices: triangles in 2D, tetrahedra in 3D.
softbody_contacts(Node) -> physics2d::SoftContacts softbody2d What the body's surface touched in the last step.
softbody_crossing(Node, [Vec2]) -> physics2d::SoftCrossing softbody2d The edges and cells a blade meets, without cutting: the blade is a segment's two points in 2D, a triangle's three in 3D.
softbody_edge(Node, int) -> physics2d::SoftEdge softbody2d Everything one edge holds.
softbody_edges(Node) -> [[int]] softbody2d Every edge as the two particle indices it joins, in the order stress reports them.
softbody_effective_particle_radius(Node) -> float softbody2d How thick the particles are: what was asked for, or what the layout worked out.
softbody_particle(Node, int) -> physics2d::SoftParticle softbody2d Everything one particle holds.
softbody_particle_count(Node) -> int softbody2d How many particles the body has, every piece torn off it included: a generator decides, not the author.
softbody_rest_area(Node) -> float softbody2d How much they enclose at rest.
softbody_stress(Node) -> [float] softbody2d Each edge's load as a fraction of its tear threshold, smoothed over tear_smoothing: 0 slack, 1 tearing; the larger of its stretch over tear_strain and its force over tear_force, and 0 while neither is set.
softbody_total_mass(Node) -> float softbody2d What the whole body weighs, every piece included.
softbody_volume_pieces(Node) -> [physics2d::SoftVolumePiece] softbody2d Each closed piece of the surface whose volume is held; an open sheet has none.
softbody_world_center_of_mass(Node) -> Vec2 softbody2d The centre of mass of the body and its pieces, which is where it is when a deformable body has no one position.
solve_ik(Node, Vec2, physics2d::IkOptions?) joint2d Move a reduced-coordinates chain so its last link reaches a world position, leaving every joint inside its limits. Options: rotation (radians to turn the link to), constrain (the world axes to match: x, y, rotation; the translation by default, every axis when rotation is given), damping (1.0), iterations (10), tolerance (0.001).
swept_aabb(Node) -> physics2d::Aabb collider2d The box the collider covers over the next fixed step, from where it is to where its body's velocity and forces carry it.
tear_cell(Node, int) softbody2d Tear one cell at the end of the next step: a particle near its middle splits across its main stretch.
tear_edge(Node, int) softbody2d Tear one edge at the end of the next step.
tear_softbody(Node, [int], [int]) -> [physics2d::SoftTear] softbody2d Tear the given edges and cells at once; answers a record for each piece it changed, the one on_torn hears.
teleport(Node, Vec2, physics2d::TeleportOptions?) body2d Move the body to a world position at once, clearing its velocity: what assigning the node's position cannot do, because the step writes that back every tick. A rotation turns it too, in radians.
time_of_impact(Node, Node, physics2d::ImpactOptions) -> physics2d::Impact? — When two moving colliders would meet, given each one's velocity. Nothing when they never do.
time_since_can_sleep(Node) -> float body2d Seconds the body has spent under its sleep thresholds; it sleeps once this reaches time_to_sleep.
total_inertia(Node) -> float body2d The body's resistance to spin, colliders included.
total_mass(Node) -> float body2d The body's total mass: its mass when it states one, or what its colliders weigh.
unpin_particle(Node, int) softbody2d Let a held particle go; it keeps the velocity it had.
velocity_at_point(Node, Vec2) -> Vec2 body2d How fast a world point on the body is moving, spin included.
voxel(Node, int, int) -> bool collider2d Whether one cell of a voxel collider is filled.
voxel_at(Node, Vec2) -> [int] collider2d The cell a world position falls in, as two whole numbers.
voxel_size(Node) -> Vec2 collider2d How big one cell of a voxel collider is, along each axis.
wake_all() — Wake every sleeping body in the 2D world.
wake_up(Node) body2d Wake the body, so the next step moves it.
wake_up_softbody(Node) softbody2d Start simulating a resting body again.
world_center_of_mass(Node) -> Vec2 body2d Where the body's whole mass sits, in world space.

Constants

name value
AXIS_ROTATION "rotation"
AXIS_X "x"
AXIS_Y "y"
BIND_CELLS "cells"
BIND_NEAREST "nearest"
BIND_PARTICLES "particles"
BODY_DYNAMIC "dynamic"
BODY_KINEMATIC "kinematic"
BODY_KINEMATIC_VELOCITY "kinematic_velocity"
BODY_STATIC "static"
CELL_COROTATIONAL "corotational"
CELL_NEO_HOOKEAN "neo_hookean"
CELL_VOLUME "volume"
COLLIDE_DYNAMIC_DYNAMIC "dynamic_dynamic"
COLLIDE_DYNAMIC_KINEMATIC "dynamic_kinematic"
COLLIDE_DYNAMIC_STATIC "dynamic_static"
COLLIDE_KINEMATIC_KINEMATIC "kinematic_kinematic"
COLLIDE_KINEMATIC_STATIC "kinematic_static"
COLLIDE_STATIC_STATIC "static_static"
COMBINE_AVERAGE "average"
COMBINE_CLAMPED_SUM "clamped_sum"
COMBINE_GEOMETRIC_MEAN "geometric_mean"
COMBINE_MAX "max"
COMBINE_MIN "min"
COMBINE_MULTIPLY "multiply"
EDGES_CHAIN "chain"
EDGES_MESH "mesh"
EDGES_OUTLINE "outline"
EXCLUDE_DYNAMIC "dynamic"
EXCLUDE_KINEMATIC "kinematic"
EXCLUDE_STATIC "static"
FILL_SOLID "solid"
FILL_SURFACE "surface"
FIT_AABB "aabb"
FIT_CONVEX_DECOMPOSITION "convex_decomposition"
FIT_CONVEX_HULL "convex_hull"
FIT_OBB "obb"
FLOW_BOTH "both"
FLOW_COMPRESSION "compression"
FLOW_TENSION "tension"
FOLLOW_PD "pd"
FOLLOW_PID "pid"
JOINT_BODY_DISABLED "body_disabled"
JOINT_DISABLED "disabled"
JOINT_ENABLED "enabled"
JOINT_FIXED "fixed"
JOINT_GENERIC "generic"
JOINT_GROOVE "groove"
JOINT_HINGE "hinge"
JOINT_ROPE "rope"
JOINT_SLIDER "slider"
JOINT_SPRING "spring"
JOINT_WAITING "waiting"
LENGTHS_ABSOLUTE "absolute"
LENGTHS_RELATIVE "relative"
METHOD_EXACT "exact"
METHOD_VHACD "vhacd"
METHOD_VOXELS "voxels"
MOTOR_MODEL_ACCELERATION "acceleration"
MOTOR_MODEL_AUTO "auto"
MOTOR_MODEL_FORCE "force"
MOTOR_OFF "off"
MOTOR_POSITION "position"
MOTOR_VELOCITY "velocity"
ORIENTATION_AUTO "auto"
ORIENTATION_SHELL "shell"
ORIENTATION_SOLID "solid"
SHAPE_CAPSULE "capsule"
SHAPE_CIRCLE "circle"
SHAPE_CONVEX_DECOMPOSITION "convex_decomposition"
SHAPE_CONVEX_HULL "convex_hull"
SHAPE_CONVEX_POLYGON "convex_polygon"
SHAPE_FIT "fit"
SHAPE_HEIGHTFIELD "heightfield"
SHAPE_MATCHING_AUTO "auto"
SHAPE_MATCHING_OFF "off"
SHAPE_MATCHING_ON "on"
SHAPE_POLYLINE "polyline"
SHAPE_RECTANGLE "rectangle"
SHAPE_SEGMENT "segment"
SHAPE_TRIANGLE "triangle"
SHAPE_TRIANGLE_MESH "triangle_mesh"
SHAPE_VOXELIZED_MESH "voxelized_mesh"
SHAPE_VOXELIZED_POINTS "voxelized_points"
SHAPE_VOXELS "voxels"
SHAPE_WORLD_BOUNDARY "world_boundary"
SOFT_CIRCLE "circle"
SOFT_CUSTOM "custom"
SOFT_GRID "grid"
SOFT_OUTLINE "outline"
SOFT_POLYGON "polygon"
SOFT_POLYLINE "polyline"
SOFT_ROPE "rope"
SOFT_SOLVER_CONSTRAINTS "constraints"
SOFT_SOLVER_FEM "fem"
SOFT_TRIANGLE_MESH "triangle_mesh"
SOFT_VOLUMETRIC "volumetric"
SWEEP_CONVERGED "converged"
SWEEP_FAILED "failed"
SWEEP_OUT_OF_ITERATIONS "out_of_iterations"
SWEEP_PENETRATING "penetrating"
TENSION_ALL "all"
TENSION_LISTED "listed"
TENSION_NONE "none"
TEST_BOTH "both"
TEST_EITHER "either"

Are you sure?