This article relates to the game "Half-Life: Alyx". Click here for more information.
This article relates to the workshop tools for "Half-Life: Alyx". Click here for more information.
This article's documentation is for Source 2. Click here for more information.

Physics Prop

From Valve Developer Community
< Half-Life: Alyx Workshop Tools‎ | Modeling
Revision as of 11:03, 16 June 2020 by Deprecated (talk | contribs) (Added HLATools page template)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This tutorial demonstrates how to construct a basic physics prop. A physics prop is an object which has a physical representation and can be interacted with in game.

Select the Physics Prop archetype

From the Document Outliner archetype dropdown, select the Physics Prop .

Physics Prop-131006971.png

While not required, selecting the Physics Prop type will provide warnings if the model is missing required nodes, such as the prop_data (see below).

Create the render mesh

Click the Add node button, and select the 'RenderMeshFile' node.

Physics Prop-131006913.png

When prompted select your input mesh file to be used.

Your mesh should now be visible in the viewport. For this example we are using a simple cone model:

Physics Prop-131007556.png

Physics Prop-131006921.png

Disable extra meshes in the input file

In this example, we are using the same mesh file for both physics and rendering, but it has separate mesh objects within the input .fbx file that are intended for physics only, so we want to disable those for the render mesh.

With the RenderMeshFileNode selected, use the Node Editor to un-check any meshes that should not be part of rendering model.

Physics Prop-131006923.png

Add a physics shape

Click the Add node button again this time selecting 'Physics Hull File'.

Physics Prop-131006920.png

This can be the same mesh file as your render mesh, but for complex meshes it may be necessary to first generate a simplified mesh to use for the physics representation.

In this example, as shown when creating the render mesh, we have meshes for both physics and rendering in the same .fbx file, so we will disable the meshes intended only for rendering.

With the PhysicsHullFile node selected, use Node Editor and un-check any meshes which should not contribute to the physics shape..

Physics Prop-131006927.png

The PhysicsHullFile node will generate a convex hull surrounding the enabled meshes. While it is selected you can see a preview of the hull.

Physics Prop-131006922.png

Adjust the hull parameters to get a better fit

The PhysicsHullFile node has several options an parameters that can be used to control exactly how it generates a hull from the input mesh.

In this case we can get a closer fit by generating multiple hulls, instead of a single hull.

Change the Import Mode to Hull Per Mesh.

Physics Prop-131006929.png

Selecting the Hull Per Mesh causes a separate hull to be generated for each of the enabled meshes in the PhysicsHullFile's mesh list.

Since these meshes were specifically constructed for the physics shape, this now results in a much better fit:

Physics Prop-131006931.png

However, these hulls are more complex than ideal, and the model could cause both performance and stability problems with the physics simulation.

Note that the number of vertices used by the hulls is currently highlighted in red because the hulls currently have too many vertices.

Physics Prop-131006932.png

Simplify the hull

Increase the Face Merge Angle to simplify the hull.

Physics Prop-131006943.png

The face merge angle is used to determine when two faces should be merged into a single face, if the angle between the two faces is greater than the merge angle then the faces will not be merged. Increasing it allows more faces to be merged, resulting in a simpler hull.

Change the Optimization Algorithm to Incremental Face Reduction.

Physics Prop-131006947.png

There are several different options for the Optimization Algorithm which one is best will vary based on the geometry of the model, try switching between them to see which one gives the best results.

At this point the hull now is simple enough while still closely matching the rendering mesh.

Physics Prop-131006949.png

Add Prop Data

All physics props must have a prop_data node. Models without prop_data cannot be used with the prop_physics entity.

This node provides the game with information about how damage should be applied to the prop.

Click the Add node button and select GenericGameData: prop_data from the list.

Physics Prop-131006965.png.

Compile the model

Click the 'Needs Compiling' button at the bottom of the Preview Outliner to save and compile the model.

Physics Prop-131006975.png.

Test the model

You can quickly test the in-game functionality of the model using the ModelDoc Editor's Game Preview mode

Click the play button in the upper left corner of the 3D viewport to start the Game Preview mode.

Physics Prop-131006977.png

Select the prop_physics entity class, then select the Spawn entity tool and click in the viewport to place instances of the model. .

Note.png Note: If you set the model archetype to Prop Physics then the prop_physics entity should already be selected by default

Physics Prop-131006978.gif

Use the Grab tool to move existing instances of the model .

Physics Prop-131007000.gif

Use the Shoot tool to test how the model will react when being shot.

Physics Prop-131007001.gif

Note that the impact effect doesn't really match the model. This can be corrected by changing the surface property of the model

Change the Surface Property of the model

With the PhysicsHullFile selected, find the Surface Property attribute in the Node Editor and select a type which is appropriate for your model.

Physics Prop-131007010.png

Note.png Note: Changing the surface property will also change the mass calculation, so picking an appropriate surface property will generally make this value more reasonable.

Recompile the model. You should now see a more appropriate impact effect when shooting the model.

Physics Prop-131007015.gif

You now have a functional model that can be placed as a prop_physics entity and can be interacted with using the physics system in game.