Skip to content

Falling boxes with Box2D

Updated

Box2D, the 2D physics engine compiled to JavaScript, imported from a CDN, drops six boxes on a ground seen through an Orthographic Camera, and a click kicks a box up: the script steps the Box2D world every frame and copies each body’s position and angle to its box.

Watch the boxes fall and stack. Click a box to kick it up, or click the scene and press Space to drop them all again.

Falling boxes with Box2D

The script is explained step by step in Falling boxes with Box2D.

Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.

Box2dStack.xrproj