Physics
From C4 Engine Wiki
The Physics Page is a tool page in the C4 Engine World Editor. It can be displayed by selecting Physics from the Page menu.
Shown below, the Physics Page contains tools for creating four types of physics-related nodes in a scene. The first type of node is simply called the physics node, and exactly one of these needs to be present in any world that uses the built-in physics functionality. The other three types of nodes are the following:
- Shapes that define the volumes of rigid bodies controlled by the physics simulation.
- Joints that connect rigid bodies to each other or to the static environment in specific ways.
- Fields that define volume inside which rigid bodies experience certain forces.
The Physics Node
Placing a physics node in a world tells the C4 Engine to use its own built-in physics simulation in that world. If a physics node is not present, then no built-in physics simulation is run by the engine, and any rigid bodies in the level will not move. If you are using an external physics library, then leaving the physics node out of your worlds effectively disables the built-in physics functionality in C4. (When the C4 physics simulation is disabled, it has zero performance cost.)
A single physics node should be placed in the infinite zone of any world for which the built-in physics simulation should be enabled. This is done by selecting the physics node tool in the Physics page and clicking in the scene with the infinite zone set as the target zone. The physics node can also be placed in the infinite zone by selecting the physics node tool and then clicking on the infinite zone node in the scene graph viewport.
A physics controller is automatically assigned to the physics node, and this should not be changed. The physics controller holds global simulation settings that can be accessed in the Node Info window. Currently, the only global setting is the acceleration of gravity, and its default value is 9.8 m/s2.
Shapes
A physics object is created by assigning a rigid body controller to a node and creating one or more shapes as subnodes of that node. The shapes define the volume occupied by the physics object as seen by the physics simulation, and they are always fixed relative to each other within a single object. Each shape can have a different density, and the engine automatically calculates properties such as the center of mass and the inertia tensor.
Shape nodes are created by selecting one of the available shapes in the Physics page and drawing it in the scene. The Move tool should be used in the scene graph viewport to make each shape a subnode of the node to which the rigid body controller is assigned.
The shape density is specified in the Node Info window. The density is measured in units of kg/dm3 (kilograms per cubic decimeter), which is equivalent to Mg/m3 (metric tons per cubic meter). The density setting displays the volume in m3, so the density for a given mass in kilograms can be determined by dividing the mass by 1000 and then dividing by the volume.
Joints
Rigid bodies can be connected to each other or to the static environment by using joint nodes. Each joint node has two connectors called %Body1 and %Body2, and these should be connected to the rigid bodies that are to be joined. If only one rigid body is connected, then the joint is static, meaning that it attaches the rigid body to the static environment. Otherwise, the joint attaches two rigid bodies together.
For those types of joints that have an axis of rotation (such as the revolute joint), rotation is allowed about the joint's local z axis. This is represented by the blue arrow shown on the gizmo in the World Editor.
Fields
A field node represents a volume inside of which a force can be applied to physics objects. Forces are applied to objects in a field through the extensible Force class. After a field has been created in the World Editor, a force can be assigned to that field in the Node Info window.
There are two forces built into the engine, a fluid force and a wind force. The fluid force applies buoyancy and drag, and it can be configured to simulate a current. The wind force applies air drag for a wind current. Custom forces can be defined by creating subclasses of Force and registering them with the engine.

