Documentation menu

Physics3D

Quick Start

Physics3D makes 3D objects fall, bump, roll, and stop on the floor. Start by making one world, one floor, and one shape. A normal shape can move. A shape whose name starts with static_ stays still.

New to coding?

Copy the examples exactly first. Run them. Then change one number or word and run them again. You are not expected to memorize the command lists.

1

Step 1: Make a tiny world

The world holds the physics. The floor stops objects from falling forever. The crate, ball, and wall are the things inside the world.

Try this code
using Physics3D;  # Turn on the 3D physics tools

world = Physics3D.world(0, -9.81, 0);  # Make a world with downward gravity
Physics3D.floor(world);  # Add ground so things do not fall forever

crate = Physics3D.box(world, 0, 6, 0, 2, 2, 2);  # A falling box
ball = Physics3D.sphere(world, 3, 8, 0, 0.5);  # A falling ball
wall = Physics3D.static_box(world, 6, 2, 0, 1, 4, 8);  # A wall that stays still

Physics3D.material(world, ball, 0.7, 0.3);  # Make the ball bouncy and a little grippy
Physics3D.apply_impulse(world, ball, -4, 2, 0);  # Give the ball one quick push
Physics3D.step(world, 1 / 60);  # Move physics forward one frame
2

Step 2: Move time forward

Physics only moves when you call step. Call it once each frame. The other commands are listed here for when you need them. MAKO automatically checks fast objects more carefully so they do not skip through thin walls.

Try this code
world(gx=0, gy=-9.81, gz=0, fixed_step=1/60, substeps=4)
step(world, delta=fixed_step)
body_count(world)
clear(world)
destroy_world(world)