Create a Physics Prop
Start by creating a simple box physics prop out of primitives.
This tutorial uses primitive shapes for rendering and physics, but references to mesh files (.fbx, .dmx) can be directly substituted. Import filters make it easy to create a single FBX file that contains many mesh parts that can then be referenced by separate breakpieces.
- Add RenderPrimitiveBox and PhysicsShapeBox nodes with origin (0,0,8) and dimensions (16,16,16)
- Apply the 'prop.wood_box' surface property to the physics box
- Add a prop_data node to indicate that this model is intended to be used as a physics prop.
- Now use the ModelDoc game preview to verify that you can spawn the model as a prop_physics and move it around
Add a BreakPiece
- First edit the prop_data to specify a health - this will allow the prop to take damage and break if it has any breakpices:
- Add a BreakPieceEmbedded node - this node will contain everything required to have a simple breakpiece without authoring it as a separate model.
- Under the BreakPieceEmbedded node, add a RenderPrimitiveBox and PhysicsShapeBox with origin (0,4,8) and dimension (15,7,15) - you can do this by copy-pasting the boxes you created earlier.
- For clarity assign the renderbox the primary_red.vmat material so it's very clear when the object breaks.
Each BreakPieceEmbedded node is effectively a small embedded sub-document that can contain most nodes. (NOTE: Due to a limitation in the editor it may warn about some nodes but most will work just fine.) When the parent model compiles, each BreakPieceEmbedded will be extracted and compiled into a separate vmdl_c that is then referenced by the parent model's break info.
Add a Second BreakPiece
Breaking something isn't very interesting if it only breaks into a single piece. Right-click your BreakPiece and select "duplicate" then change the origin of the new boxes to (0,-4,8)
We made breakpieces slightly smaller than the original box in order to guarantee that they don't overlap when they're spawned. The physics engine is fairly resilient in the face of overlapping objects, but it's always better to avoid when possible!
Test Your Breakable
Use the game preview to spawn a prop_physics and use the shoot tool to verify that it takes damage and breaks as expected. Congratulations, you've made your first breakable model!