7. Physics
In this tutorial we will go over how you can make your models fall under gravity, and collide with the ground.
Rigid Bodies
In game physics, a rigid body is the term used to describe a simplified mesh that can be used for collision calculations. By giving a pattern a rigid body, it will be able to collide with walls or other objects, and bounce away with the correct amount of force.
As physics simulations can be quite performance intensive, the rigid bodies they work with need to be kept as simple as possible in order for the game to keep running as smoothly as possible. Waveform provides three options to choose from when deciding which rigidbody to represent your model:
Type | Description |
---|---|
Capsule | The most efficient. Good for most cylinder shaped meshes |
Box | A cube, good for cube shaped meshes |
Simplified Mesh | Use this for for more complex shapes. This will calculate the most efficent shape for the mesh it is given |
Let's assign some rigid bodies and see them in action. First open up the physics
tutorial project, and open the Compose
item. A stick man is provided here, which is already setup to work with the physics simulation. Select Enable -> Enable Physics
to run the simulation.
The man is made up of a Sphere for the head, Capsules for the arms and a Box for the body. Select View -> Physics Bodies and Wireframe
to see the actual rigid bodies in use:
If you select the patterns themselves, you will find they each have a physics block, attaching a rigid body to a bone. All rigid bodies require a bone, as they use the rig to move the model. For the arms and legs we have:
Here we have specified the capsule
, as well the name of the bone to attach to. A bone must always be specified, and Waveform will try it's best to fit the shape to the part of the pattern that the bone controls. Next, the head:
As the head is spherical, it makes sense to also use the sphere
for the physics body too.
Here we use a box
to surround the body, and we also scale up in the X
and Z
axis slightly in order to get a better fit than the default. As Waveform won't always get the default correct, you have the option to attach any of the transform
blocks to the right-side in order to tweak the final physics shape. The blocks are always read in the order Scale
, Rotate
then Translate
.
There is also the option to use a
Simplified Mesh
, which is effectively a convex hull fitted to the shape of your pattern. Whilst this will result in the best possible fit for your model, it is also intensive for real time physics engines to work with, and so it's better to pick one of the above simpler options instead.
Joints
Physics bodies will follow the constraints of the rig they are attached to, respecting the parent -> child
relationships between the bones. Select the cylinder_chain
compose item, and you can see than the Bone
input has been specified, connecting the lower capsule to the upper capsule. Try removing the bone input and enabling physics again. You should see that when they impact the floor, they bounce off in different directions as they are no longer connected to each other.
Connecting the physics bodies together is how we form a ragdoll
. If you select the compose
item you will see that all the man's bones are connected to the base layer. Thus all the rigid bodies are also connected together when in the physics simulation. Try removing all of the Bone
inputs here to see the man fall apart when he hits the floor.
Note that you can also interact with the simulation by left-clicking and dragging the model around. See how far you can throw him!